I am interested to find out how many objects were reclaimed by the garbage co开发者_如何转开发llector after I run the following code.
if (ObjectsOutstanding > GCThreshold) {
System.GC.Collect();
}
One easy way of doing this for your own custom-types would be to increment and track some counter in their finalizers.
e.g.
public class MyCustomType
{
public static int NumFinalizersCalled;
~MyCustomType()
{
Interlocked.Increment(ref NumFinalizersCalled);
}
}
In the Visual Studio debugger you can use the SOS library in the immediate window. There are several GC methods that give you the information you need. I don't know if this is what you want, but it is a starting point.
精彩评论