Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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 (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?

like image 265
galbarm Avatar asked Mar 07 '11 08:03

galbarm


2 Answers

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.

like image 165
sloth Avatar answered Sep 23 '22 03:09

sloth


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.

like image 42
Ian Ringrose Avatar answered Sep 25 '22 03:09

Ian Ringrose