Counting number of GC cleanups on an object

Posted by tsps on Stack Overflow See other posts from Stack Overflow or by tsps
Published on 2010-05-03T14:38:41Z Indexed on 2010/05/03 14:48 UTC
Read the original article Hit count: 212

Filed under:
|
|

How do I keep a count of the number of times that objects of a specific class (type?) are getting disposed in the lifetime of my application. Imagine I have a class A, now, I want to count how many times the objects of A get collected by the GC.

I hope I am phrasing this right because I was asked this in an interview today and the answer I gave did not satisfy the interviewer. And this is what I imagine he was trying to ask.

What I said was that one could keep a static field called count in the class A and increment it in the Finalize() call of that object.

The answer he was expecting was something called a static block. I've never heard of this in .NET/C#. Can someone explain what's this static block?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET