0

I'm trying to figure out some memory issue in my program, I dumped the memory from a stress testing and then import to .NET Memory Profiler, there's very strange thing for me that seems an object[] which contains only 92 instances of String was located at LOH.

As I know, only the array have massive elements would be assigned to LOH and no matter the element type is, since both Value type and reference type only occupy 4 bytes memory addresses. so if we say 85K is the minimal size to put on LOH, so an array need reach 85000/4 = 21000 elements.

The Profiler say it's on the LOH, sorry i can't show that words which only appears when mouse is on that object[]

Profiler say #404,147 was on LOH Checking the 92 elements' detail. All object[] elements were listed, instance bytes is not big and I think it's totally irrelevant

1
  • That profiler is worth what you paid for it. That the array has 92 string references does not say anything about how large the array actually is. The rest of the elements can of course contain null or reference an interned string. Nov 8, 2013 at 11:02

1 Answer 1

1

The .NET runtime implements static fields using object[] arrays as storage, so the object[] arrays you see on the LOH are most likely used as containers for static fields.

To optimize access to a static field, the runtime wants to use direct memory access to the field, but since the field is stored as an entry in a managed array, the array can normally be moved in memory. To prevent the field storage from moving, the object[] array could be pinned in memory, but that would significantly affect the performance of the garbage collector. Instead, the object[] array is allocated in the large object heap, even though the size is much smaller than a normal large object. Placing the array on the large heap will also prevent the instance from being moved, and will provide benefits for the generational garbage collector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.