What's the meaning of 'Free' block of Large object heap when dump with WinDbg
Asked Answered
B

2

7

I'm investigating the memory leak issue with PerfMon & WinDbg. I was noticed the 'Large memory heap' counter is increased from 10MB to 37MB. After force a GC it only can reduce to 28MB. enter image description here

(No matter how many time I repeate the operation(create/destroy), after GC, the large object heap is stable at 28MB).

I would like know which objects cause leak issue, so I run the WinDbg with the '!Dumpheap -min 85000' comand. Captured two snapshots, the first one was done before memory leak; The second one is after memory leak:

Before:

       MT    Count    TotalSize Class Name
 6f39fb08        1        89024 System.String
 6f3a4aa0        1       107336 System.Byte[]
 6f356d84        2       262176 System.Object[]
 00360e4c        1       350392 System.Collections.Generic.Dictionary`2+Entry[Int64,Int32][]
 6f3a2a94        3       592584 System.Int32[]
 00360c24        1       727072 System.Collections.Generic.Dictionary`2+Entry[String,Int64][]
 0bc78b34        4      2754488 System.Collections.Generic.Dictionary`2+Entry[Int64, AccountNode][]
 00730260       10      5375572      Free

After:

       MT    Count    TotalSize Class Name
 6f39fb08        1        89024 System.String
 6f3a4aa0        1       107336 System.Byte[]
 6f3a55d8        2       202080 System.Collections.Hashtable+bucket[]
 6f356d84        2       262176 System.Object[]
 00360e4c        1       350392 System.Collections.Generic.Dictionary`2+Entry[Int64,Int32][]
 00360c24        1       727072 System.Collections.Generic.Dictionary`2+Entry[String,Int64][]
 6f3a2a94        4       738008 System.Int32[]
 6cf02838        1       872488 System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.ComponentModel.PropertyKey, WindowsBase],[MS.Internal.ComponentModel.DependencyPropertyKind, WindowsBase]][]
 0bc78b34        4      2754488 System.Collections.Generic.Dictionary`2+Entry[Int64, AccountNode][]
 00730260       14     21881328      Free
 Total 31 objects

Camparing these two snapshot, the most difference is the size of 'Free'. its size has increased near 16MB. Can anyone tell me what's the meaning of the 'Free', is it the free space? Is the increasement caused by fragements?

According to this article, the ‘Large Object Heap Size’ performance counter seems include free space. So in my case, there isn't have too much memory leak on large object heap, only 2MB (= 28 - 10 -16), right?

Belshazzar answered 16/1, 2013 at 7:34 Comment(2)
It is not a leak. This is normal. Do not call GC.Collect(), it is very detrimental. Don't chase "leaks" until your program starts to use excessive amounts or memory or crashes with OOM. 37MB is peanuts. Educate yourself with a good book like Richter's C# via CLR.Manteltree
Thanks for your reply. I agree with you that we should not call GC.Collect() in product code. I don't understand why not chase "leaks" issue? As I know, as much 'garbage' stay in heap, as much GC happened. In my opinion, we should chase it and cut down unnecessary refrenent(i.e. unregist event), which can caused memory leak problem.Belshazzar
Q
5

FREE indicates a block of unused memory on the heap. FREE blocks on the LOH are expected, because the LOH never gets compacted. Instead, a list of FREE space is kept for the LOH. FREE blocks on the normal GC heap, with a few exceptions, indicate fragmentation due to the pinning of objects. When the GC encounters a pinned object, compaction of the segment is halted and the memory consumed by unused objects is marked as FREE. What you're seeing on the LOH is normal. Remember that the LOH is never compacted and memory segments allocated for the LOH are never freed, so the LOH never shrinks.

Quinquennium answered 16/1, 2013 at 15:9 Comment(1)
This. The most problematic part about the large object heap is this lack of compaction, which can (if you are unintentionally abusing it) lead to heap fragmentation, basically the same thing that happens to your hard drive.Grania
H
0

The meaning of large object heap is well explained here.

Large objects are objects of size greater than 85kb, stored in that area, and collected only when the generation 2 will be reclaimed.

Humanly answered 16/1, 2013 at 7:41 Comment(3)
@Devil, Thanks for your reply. However i'm not ask question about the 'large object heap' but the 'Free' item shown in WinDbg.Belshazzar
The GC during the execution of an application allocates and deallocates objects, so the heap grows, but it will not shrinked to each deallocation for performance reasons. Doing so the application can get enough room for new objects without allocate extra memory. The GC internal mechanisms, sometimes, reclaim part of the unused heap shrinking it. I think FREE is the difference between the objects size sum and currently allocated heap.Humanly
The link in the answer is deadDisestablish

© 2022 - 2024 — McMap. All rights reserved.