How do I get .NET to garbage collect aggressively?

后端 未结 12 788
情书的邮戳
情书的邮戳 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 15:10

    Use Process Explorer (from Sysinternals) to see what the Large Object Heap for your application is. Your best bet is going to be making your arrays smaller but having more of them. If you can avoid allocating your objects on the LOH then you won't get the OutOfMemoryExceptions and you won't have to call GC.Collect manually either.

    The LOH doesn't get compacted and only allocates new objects at the end of it, meaning that you can run out of space quite quickly.

提交回复
热议问题