I am looking for a way to programatically get the number of instances of a certain class type in .NET and Java.
Say for example I have class Foo. I want to be able to, in the same process, get a current count of all instance of Foo.
However I cannot modify Foo, so a static int with counting is out. Also I cannot just add all instances I make to some static list and count that. I want to be able to just say:
System.GC.numberOf< Foo >()
or something.
I was looking through the garbage collectors but I could not find any relevant methods.