.Net garbage collector. See what promotes Gen2 at runtime.

My program promotes memory in Gen2 at a very high speed (about 1 MB / s), and this leads to a performance hit when collecting the Gen2 collection. Every attempt I made to understand which objects were advanced failed, mainly due to the fact that when I opened 2 dumps in windbg, the memory from which the Gen2 size was increased was marked as β€œFree”. This made me suspect that the Pinned objects were causing the problem, but perfmon statistics show that the number of Pinned objects is very low (around 2-4).

What I'm trying to try now is to somehow determine which objects will be distributed to Gen2 at runtime. Is there any way to do this?

+8
garbage-collection debugging c # windbg
source share
4 answers

You can use WinDbg to debug such problems. Set a breakpoint in the garbage collection procedure, check the managed heap, give the garbage collection, then look at the managed heap again to see what objects are in Gen2 now.

Here are some links to get you started:

Managed Memory Leak Tracking

How to iterate objects located in a managed .NET heap?

Tess Ferrandez Blog

Memory Management and .NET Garbage Collection Research

Sorry, this is not a direct, detailed answer to your question, but it should give you a starting point.

+5
source share

There are several 3 third-party memory profiles for .NET , try them, most of them allow you to go through a trial period. I expect that any of the leading memory profilers will allow you to quickly see what is happening.

+2
source share

You can highlight a lot of LOH. Here is a way to have a break point when distributing LOH. bp mscorwks!wks::gc_heap::allocate_large_object "!CLRStack" inside Winbdg.

NTN

+1
source share

You can try to force the gen (0) and gen (1) collections and take a picture right after you finish

 GC.Collect(1,GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); CreateDump(); 

Also, what flavor of GC do you use?

0
source share

All Articles