How do I get .NET to garbage collect aggressively?

后端 未结 12 772
情书的邮戳
情书的邮戳 2020-12-02 14:33

I have an application that is used in image processing, and I find myself typically allocating arrays in the 4000x4000 ushort size, as well as the occasional float and the l

12条回答
  •  不思量自难忘°
    2020-12-02 14:56

    Here are some articles detailing problems with the Large Object Heap. It sounds like what you might be running into.

    http://connect.microsoft.com/VisualStudio/feedback/details/521147/large-object-heap-fragmentation-causes-outofmemoryexception

    Dangers of the large object heap:
    http://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/

    Here is a link on how to collect data on the Large Object Heap (LOH):
    http://msdn.microsoft.com/en-us/magazine/cc534993.aspx

    According to this, it seems there is no way to compact the LOH. I can't find anything newer that explicitly says how to do it, and so it seems that it hasn't changed in the 2.0 runtime:
    http://blogs.msdn.com/maoni/archive/2006/04/18/large-object-heap.aspx

    The simple way of handling the issue is to make small objects if at all possible. Your other option to is to create only a few large objects and reuse them over and over. Not an idea situation, but it might be better than re-writing the object structure. Since you did say that the created objects (arrays) are of different sizes, it might be difficult, but it could keep the application from crashing.

提交回复
热议问题