To do this entirely inside the application, you can make an instance counter, but it must be explicitly encoded and managed within each class - there is no silver bullet that I know of, to allow you to request a framework from within the executable code to find out how many copies alive.
What you are asking is really a profiler domain. You can purchase it or create it yourself, but it requires your application to run as a child of the profiler. By the way, riding on your own is not an easy task.
If you want to consider the instance counter, it should be something like this:
public class MyClass : IDisposable
public MyClass()
{
++ClassInstances;
}
public void Dispose()
{
--ClassInstances;
}
private static new object _ClassInstancesLock;
private static int _ClassInstances;
private static int ClassInstances
{
get
{
lock (_ClassInstancesLock)
{
return _ClassInstances
}
}
}
, ; 0% ( ), Dispose, , GC. , , , - , , windbg.
: , , , , . , IMO, ANTS Memory Profiler. 5 - , SKU ( ), Memory Profiler 5.0 . , , -.
0 , , ANTS, . .