Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does .NET have something similar to Java's garbage collection log?

Does .NET have something similar to Java's garbage collection log? I want to write GC stats to a log in a production application. Google doesn't tell my anything useful and SO doesn't seem to have any related questions either.

Thanks

like image 590
Shahbaz Avatar asked Jan 08 '10 21:01

Shahbaz


2 Answers

GC stats are available as performance counters. In perfmon they're displayed under the ".NET CLR Memory" category. You can access perf counters programmatically via the System.Diagnostics namespace (the PerformanceCounterXxx classes), or use Server Explorer to create handy wrappers.

Note that these are statistics and do not provide detailed per-object logging.

like image 87
itowlson Avatar answered Oct 19 '22 16:10

itowlson


When the perf stats tell you there's a problem, you can dive in with a debugger (windbg) to find leaks. The !GCRoot command allows you to find out why memory isn't being collected. See this blogpost for more info

like image 34
Sander Rijken Avatar answered Oct 19 '22 16:10

Sander Rijken