Sobes.tech
Junior — Middle

What objects in .NET fall into the Large Object Heap and how can they be identified?.

sobes.tech AI

Answer from AI

In .NET, objects of size 85,000 bytes and larger are placed in the Large Object Heap (LOH). These are usually large arrays (for example, byte arrays, strings, or other types) that consume a lot of memory.

LOH is used to optimize handling large objects to avoid frequent memory fragmentation and copying costs during garbage collection.

To identify objects in LOH, profiling tools such as dotMemory or the built-in Visual Studio Diagnostic Tools can be used. In the profiler, objects with a size >= 85,000 bytes will be displayed as LOH objects.

Example: an int array with 25,000 elements (each int takes 4 bytes, totaling 100,000 bytes) will be placed in LOH.

int[] largeArray = new int[25000]; // This array will be in LOH