1

What is, by default, the strategy used by the .NET framework to compact the large object heap?

  • never compacted
  • compacted after a while (not as aggressively as generational heap)

What holds? If "after a while", are there a few details about "how long" or "when"?

(I'm interested in .NET framework versions higher than 4.5)

Benoit Sanchez
  • 681
  • 6
  • 21

1 Answers1

2

By default, the LOH is not compacted at all. Because that could be expensive.

From 4.5.1 on, you can us GCSettings to change that. The choices are CompactOnce and Never.

So you can manually trigger a Compaction, driven by your application logic.

The LOH is only collected (sweeped) during a Generation 2 collection. That may cause your "after a while" confusion. But collection is not compaction.

H H
  • 263,252
  • 30
  • 330
  • 514
  • Thanks. But your phrasing suggests GCSettings.LargeObjectHeapCompactionMode is set forever while it's only a one shot assignation and will be reset after next blocking GC. https://learn.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode?view=netframework-4.7.2. I think you should make it clear. – Benoit Sanchez Nov 21 '18 at 13:21
  • Yes, it is only active for one Collect. That is what I meant with manually. – H H Nov 21 '18 at 13:46