Back to results for “Memory Management”
.NET › Diagnostics & Performance

What is the Large Object Heap (LOH), and why do objects larger than 85,000 bytes behave differently in the garbage collector?

Intermediate

Answer

Objects 85,000 bytes or larger are allocated on the Large Object Heap, a separate heap segment managed differently from the normal small-object heap -- LOH objects are collected only during gen-2 (full) collections and, historically, the LOH was never compacted (leading to potential fragmentation), though modern .NET can optionally compact it. Frequently allocating and discarding large objects (like large arrays or buffers) can cause LOH fragmentation and more frequent expensive full GCs, making techniques like buffer pooling (ArrayPool<T>) particularly valuable for large, frequently-allocated objects.
// This large array allocation goes to the LOH (>= 85,000 bytes)
byte[] largeBuffer = new byte[100_000];

// Better: rent from a pool instead of repeatedly allocating large arrays
byte[] pooledBuffer = ArrayPool<byte>.Shared.Rent(100_000);
try { /* use it */ }
finally { ArrayPool<byte>.Shared.Return(pooledBuffer); }
Real-world example An image-processing service handling large byte array buffers switches from `new byte[]` allocations to ArrayPool<byte>.Shared.Rent/Return, significantly reducing LOH fragmentation and full GC frequency under sustained high throughput.

Common follow-ups: How do you enable LOH compaction, and what's its performance cost when triggered?;What's the threshold and how was 85,000 bytes specifically chosen?