How to fix Error 157 on Windows 11

Windows 11 Error 157: “The segment is already discarded and cannot be locked”

Why This Error Happens

Error 157 occurs when an application attempts to access a memory-mapped segment that has already been released by the system, typically due to a race condition between processes or a premature termination of a shared memory handle. This is commonly triggered by corrupted DLL files, outdated device drivers, or applications improperly managing memory allocation during multitasking. In some cases, disk corruption on the volume hosting the application’s cache or virtual memory files can also cause this discrepancy.

Step-by-Step Resolution Guide

  1. Run System File Checker to repair corrupted system files:
    Open Command Prompt as Administrator and run:
   sfc /scannow

Allow the scan to complete fully before restarting your PC.

  1. Check and repair disk errors:
    Run the Deployment Image Servicing and Management tool followed by CHKDSK:
   DISM /Online /Cleanup-Image /RestoreHealth
   chkdsk C: /f /r

You will be prompted to schedule the CHKDSK scan on next restart—confirm and reboot.

  1. Update or roll back the relevant device driver:
    Navigate to Settings > Windows Update > Advanced options > Optional updates > Driver updates. If the error started after a recent driver update, instead go to Device Manager, right-click the affected hardware, select Properties > Driver tab > Roll Back Driver.

  2. Increase virtual memory (paging file) allocation:
    Go to Control Panel > System > Advanced system settings > Performance Settings > Advanced tab > Virtual Memory > Change. Uncheck “Automatically manage paging file size,” select your system drive, choose Custom size, and set an initial size of 1.5x your RAM and a maximum of 3x your RAM.

  3. Reset or reinstall the affected application:
    If the error is tied to a specific program, go to Settings > Apps > Installed apps, locate the application, click the three-dot menu, and select Advanced options > Reset. If the issue persists, uninstall and reinstall the application using the latest installer from the vendor.

Alternative or Verification Steps

  • Verify the fix: Reopen the application or trigger the action that previously caused Error 157, and monitor Event Viewer (eventvwr.msc) under Windows Logs > Application to confirm no new Error 157 entries appear.
  • Alternative solution: If the error persists, create a new local user profile (Settings > Accounts > Other users > Add account) and test the application there—this isolates whether the issue is caused by a corrupted user profile rather than a system-wide fault.