tags:

views:

100

answers:

3

I wonder if there is a way to either programatically or using a third party tool (profiler?) get an overview of how many instances of a class are currently active in the AppDomain (including or excluding derived classes), and even better, where they are allocated (not sure if that is even possible).

I know that I could change my own classes to include some running counter somehow, but I also want this for (managed) classes that I do not control.

Is that even possible? Some hints or keywords would be helpful :)

+4  A: 

I think what you would want to use is SOS and the Windows Debugging Toolkit.

There is a great blog from Tess Ferandez which has tons of information on using it.

http://blogs.msdn.com/tess/

mannu
+1  A: 

I'm almost hesitant to answer because there's got to be a bunch of easier ways, but using adplus to take a hang dump, and then use WinDbg with Son of Strike to navigate the dump file.

You can also get a profiler that will assist you with some rudimentary analysis on the hang dump.

Pseudo Masochist
+1  A: 

I don't think that there's a neat way to do this with reflection in the same way as you can enumerate classes or methods, say. CLR Profiler will attach to a process and then report how many instances of each class are allocated. In theory you could write your own code against the same API that CLR Profiler uses, but I suspect that it would be a lot of effort and not necessarily enlightening.

stevemegson