C# › Memory & Garbage Collection
What is the Large Object Heap (LOH), and why do objects allocated there behave differently from regular small objects?
AdvancedAnswer
Objects 85,000 bytes or larger are allocated on a SEPARATE Large Object Heap, which is NOT compacted by default during garbage collection (unlike the regular generational heap) — this can lead to HEAP FRAGMENTATION over time as large objects are freed and re-allocated, since the LOH's free space between surviving large objects can't always be reused efficiently.
byte[] largeArray = new byte[100_000]; // allocated on the LOH, not the regular generational heap
// Repeatedly allocating/freeing large arrays like this can fragment the LOH over time
// Mitigation: enable LOH compaction explicitly when needed
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;Real-world example Diagnosing a long-running service's gradually increasing memory footprint traced to LOH fragmentation from repeated large buffer allocations.