What causes memory fragmentation in .NET

后端 未结 3 1585
南方客
南方客 2020-12-02 16:57

I am using Red Gates ANTS memory profiler to debug a memory leak. It keeps warning me that:

Memory Fragmentation may be causing .NET to reserver too

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 17:18

    The GC heap treats large object allocations differently. It doesn't compact them, but instead just combines adjacent free blocks (like a traditional unmanaged memory store).

    More info here: http://msdn.microsoft.com/en-us/magazine/cc534993.aspx

    So the best strategy with very large objects is to allocate them once and then hold on to them and reuse them.

提交回复
热议问题