Skip to content

Large Object Heap LOH

Context: In .NET, objects larger than 85,000 bytes (85 KB) are allocated on a special heap called the Large Object Heap (LOH). The LOH is not compacted by default because moving large objects would be expensive. Instead, the GC uses a free‑list algorithm to manage LOH memory. This can lead to fragmentation over time. Since .NET 5, you can manually compact the LOH, but it is still generally avoided for performance reasons.

using System;
public class LOHDemo
{
public static void AllocateLargeObject()
{
// This array will go to LOH because it is > 85KB
// 85,000 bytes / 8 bytes per double ≈ 10,625 doubles
double[] largeArray = new double[11000];
Console.WriteLine($"Is on LOH? {GC.GetGeneration(largeArray) == 2}"); // Usually true
}
}
Terminal window
dotnet run
Is on LOH? True
  • LOH objects are always generation 2.
  • Frequent LOH allocations can cause memory fragmentation.
  • Use ArrayPool<T> or object pooling to reuse large buffers.

Image processing – Loading large bitmaps (e.g., 4K images) allocates large byte arrays on the LOH. Reusing buffers via ArrayPool<byte> prevents fragmentation and reduces GC pressure.
See .NET docs on LOH.