Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if GC.Collect() was run manually?

I suspect a library I'm using is violently calling GC.Collect(), which is causing issues. How can I confirm if such a manually triggered collection is indeed happening?

My program has high memory throughput itself, but many 100 Gen 2 collections per second still seem very unlikely to me, especially considering it's using only a few 100 MB of RAM.

like image 627
mafu Avatar asked Dec 06 '25 07:12

mafu


1 Answers

There is a performance counter for that, "Induced GC" ticks up every time GC.Collect() is called. Use Perfmon.exe to look at it, right-click the graph > Add Counters > .NET CLR Memory > # Induced GC > select your exe.

A decent decompiler is always useful as well (ILSpy, Reflector, etc), you can tell the author exactly what method he needs to fix.

like image 73
Hans Passant Avatar answered Dec 07 '25 20:12

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!