.Net Garbage Collector - See what is promoted to Gen2 during Runtime
My program is promoting memory to Gen2 at a very high rate (about 1MB/Sec) and it causes performance hit when Gen2 collection occurs. Every attempt I made to understand which objects were promoted failed - mainly due to the fact that when I opened 2 dumps in windbg, the memory from which the increase of Gen2 size was made up, was marked as "Free". It led me to suspect that Pinned objects are causing the problem but perfmon statistics shows that # of Pinned objects is very low (abo开发者_C百科ut 2-4).
What I'm thinking about trying now is to somehow identify which objects are promoted to Gen2 in runtime. Is there a method for doing this?
You could use WinDbg to debug such issues. Set a breakpoint on the garbage collection routine, examine the managed heap, let the garbage collection occur, then examine the managed heap again to see which objects are in Gen2 now.
Here are some links to start with:
Tracking down managed memory leaks
How to iterate on the objects present in the .NET managed heap?
Tess Ferrandez' blog
Investigating .NET Memory Management and Garbage Collection
Sorry that's not an direct, detailed answer to your question, but it should give you a starting point.
There are a few 3 party memory profilers for .NET, give them a try, most of them allow you a free trial period. I expect any of the leading memory profilers will let you see what is going on quickly.
You could be allocating a lot of LOH. Here is a way to have a break-point on LOH allocation.
bp mscorwks!wks::gc_heap::allocate_large_object “!CLRStack”
within Winbdg.
HTH
You could try forcing gen(0) and gen(1) collections and take a snapshot immediately after it finishes running
GC.Collect(1,GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
CreateDump();
Also, what kind of GC flavour are your using?
精彩评论