8

Possible Duplicate:
Monitoring Garbage Collector in C#

I'd like to know how often garbage collection is run in my C# application so that I can log the timestamps for later analysis.

Is there maybe some event or something similar that is fired before or after garbage collection so that I know when exactly garbage collection happened?

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • 5
    [GC.RegisterForFullGCNotification](http://msdn.microsoft.com/en-us/library/system.gc.registerforfullgcnotification.aspx) – Tim Schmelter Nov 22 '12 at 08:14
  • I'm guessing you're doing this for performance monitoring? Maybe this will be helpful: http://msdn.microsoft.com/en-us/library/ee851764.aspx – Phil Gan Nov 22 '12 at 08:20
  • 1
    Doesn't that work only for FULL collections? There's a nice piece of code from Jeffrey Richter, where he has a "dummy" object that creates a new instance of "dummy", whenever the Finalize method is called. Since this object is created in gen0, you catch any collection. Does RegisterForFullGCNotification also catches when all objects in gen0 get collected and none is promoted to gen1? – igrimpe Nov 22 '12 at 08:22

1 Answers1

1

Have a look at performance monitor (perfmon) and memory performance counters

Drew
  • 1,277
  • 3
  • 21
  • 39
Maxim Zabolotskikh
  • 3,091
  • 20
  • 21