Getting OutofMemoryException at runtime with the message “Insufficient memory to continue the execution of the program”

后端 未结 2 403
一向
一向 2021-01-22 09:39

I am getting OutofMemoryException at runtime with the message \"Insufficient memory to continue the execution of the program.\". I am loading the images at the start of program.

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 10:35

    Is there any possibility to use more memory of the system or somehow other solution.

    Switching to 64bit is the only simple option.

    There is an underlying .NET per object 1GB limit (also applies to 64bit), but this isn't your problem. To create an object .NET needs there to be enough contiguous free memory in the process. Once you have a few very large (>250MB) large objects in process it is increasingly unlikely enough continuous address space is going to be available.

    Options:

    • Use multiple processes and interprocess communications—with all the additional complexity that brings (especially in failure cases).
    • Only load one image at a time.
    • 64bit.

    Also have a read of "Windows Internals" on how Windows manages memory, then on how the .NET GC manages memory for background. There will be no substitute for knowing what is going on when you are pushing so much data around. (Tools like VMMap will help, but only if you have a core understanding of how it all works.)

提交回复
热议问题