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 (about 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With