Interview frequency: …
Short answer
It is an area for objects larger than 85,000 bytes (such as large arrays); it is not compacted by default to avoid moving large data, leaving memory gaps that can lead to OOM.
Explanation
Copying objects of 85KB or more during Garbage Collection is expensive, so the GC used to reclaim them without Compaction, leaving gaps between freed areas. Repeatedly allocating and deleting large arrays fragments memory, and the server may be unable to find a contiguous region for a new object, causing an OutOfMemoryException. Use ArrayPool<T> to reuse large arrays.
Code example
// Use ArrayPool to avoid LOH allocations and fragmentation
var pool = ArrayPool<byte>.Shared;
byte[] buffer = pool.Rent(100_000); // Rent from the Pool
try {
// Process the data
} finally {
pool.Return(buffer); // Return to the Pool
}Common mistakes
- Allocating large temporary byte arrays for every file-processing request instead of renting them from ArrayPool.