How can I find out how many objects are created of a class in C#?
Is this a class that you've designed?
If so, add a counter to the class that is incremented in the constructor and decremented in Dispose.
Potentially you could make this a performance counter so you can track it in Performance Monitor.
You'd have to put a static counter in that was incremented on construction:
public class Foo
{
private static long instanceCount;
public Foo()
{
// Increment in atomic and thread-safe manner
Interlocked.Increment(ref instanceCount);
}
}
A couple of notes:
System.String
created, for example - at least not without hooking into the debugging/profiling APIWhy do you want this information, out of interest?