Troubleshooting ERROR_NOT_ENOUGH_MEMORY

后端 未结 4 953
孤城傲影
孤城傲影 2021-01-03 03:32

Our application is failing on one specific user\'s computer with ERROR_NOT_ENOUGH_MEMORY (\"Not enough storage is available to process this command\").

相关标签:
4条回答
  • 2021-01-03 04:23

    A more common cause this error than any of those you've listed is fragmentation of Virtual Memory Space. This a situation where whilst the total free memory is quite reasonable the free space is fragmented with various bits of the virtual memory space being currently allocated. Hence you can get an out of memory error when a request for memory cannot be satisfied by a single contiguous block despite the being enough in total free.

    0 讨论(0)
  • 2021-01-03 04:26

    The culprit in this case was CreateCompatibleBitmap. Apparently Windows may enforce fairly strict systemwide limits on the memory available for device-dependent bitmaps (see, e.g, this mailing list discussion), even if your system otherwise has plenty of memory and plenty of GDI resources. (These systemwide limits are apparently because Windows may allocate device-dependent bitmaps in the video card's memory.)

    The solution is simply to use device-independent bitmaps (DIBs) instead (although these may not offer quite as good of a performance). This KB article describes how to pick the optimal DIB format for a device.

    Other candidates for resource limits (from others' answers and my own research):

    • GDI resources (from this answer) - easily checked with GDIView
    • Virtual memory fragmentation (from this answer)
    • Desktop heap - see here or here
    0 讨论(0)
  • 2021-01-03 04:30

    Check all the possibilities.

    GDI-problems can be monitored using the free GDIView utility. Its a single file that users can start without a installer.

    Also, install the ProcessExplorer on the machine concerned.

    If you have no access to the machine, ask the user to make screenshots of the status monitored by the applications. Very likeley, this will give you some hint.

    0 讨论(0)
  • 2021-01-03 04:30

    My answer may be a little bit late but, from my late experience with that same issue, doing all the tests, going step by step, creating DC, releasing it, using DIBSection instead of CompatibleBitmap, using leak GDI/Memory tools, etc.

    In the end (LOL) I found that:

    I was switching the priority of these two calls, then the whole problem was fixed.

    DeleteDC(hdc);       //do it first (always before deleting objects)
    DeleteObject(obj);
    
    0 讨论(0)
提交回复
热议问题