GC cleanup count on site

How can I calculate the number of times that objects of a certain class (type?) Fall during the life of my application. Imagine that I have class A, now I want to calculate how many times objects A are assembled by GC.

I hope that I will formulate this right because I was asked about this in an interview today, and the answer I gave did not satisfy the interviewer. And that is what I think he was trying to ask.

I said that you can save a static field called count in class A and increase it in a call to Finalize () of this object.

The answer he expected was called a static block. I have never heard of this in .NET / C #. Can someone explain what this static block is?

+5
source share
3 answers

Use a tool such as memprofiler , Redgate Ants , dotTrace , CLR Profiler (requires administrator rights for .NET 3.5 obviously ) or the Visual Studio batch edition.

+1
source

Maybe he meant the static constructor for the class?

public class Foo {

   public static Foo() { /* gets called once before first operator new */ }

}
0
source

- Static Constructor #. . , , . , , - IDisposable, disposeCount Dispose , Finalize. , , :)

0

All Articles