mafu
mafu

Reputation: 32730

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.

Upvotes: 3

Views: 104

Answers (1)

Hans Passant
Hans Passant

Reputation: 942358

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.

Upvotes: 4

Related Questions