Large Object Heap Compaction, when is it good?

Allocations >= 85 KB go onto the LOH. Compacting the LOH is not bad — it’s just that LOH fragmentation isn’t something the great majority of apps need to worry about, so for them it’s not worth the expense of compacting.

Fragmentation occurs when you allocate several large objects and they all get taken from the same page of address space, then let some of those objects get collected. The remaining free space in that page might be unusable because it is too small, or even simply “forgotten” in the sense that the allocator won’t ever reconsider using it again.

Eventually there are fewer and fewer clean pages to use, so the allocator will start to slow down as it forcibly moves objects or even start throwing OutOfMemory exceptions. Compaction moves those objects to new pages, reclaiming that free space.

Does your app have this object usage pattern? Most don’t. And on 64-bit platforms, you might not even notice it as there’s quite a bit more address space to fragment before it becomes a huge issue.

Leave a Comment