Count of objects instantiated?

  • Thread starter Thread starter Philip Daniels
  • Start date Start date
P

Philip Daniels

Is there any function in the CLR that can give me a count, by type, of
the number of objects currently instantiated?
 
Hello, Philip!

PD> Is there any function in the CLR that can give me a count, by type, of
PD> the number of objects currently instantiated?

In order to know that - you'll have to use Profiling API.

Look at for more details
( http://msdn.microsoft.com/msdnmag/issues/01/12/hood/ )
( http://www.blong.com/Conferences/DCon2003/Internals/Profiling.htm )

Or if you want to know the instances number of your custom type, then
you can create objects factory, where necessary count tracking will be
implemented...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hello, Philip!

PD> Is there any function in the CLR that can give me a count, by type, of
PD> the number of objects currently instantiated?

In order to know that - you'll have to use Profiling API.

Thanks, Vadym, that was quick.

Had a quick look, and ICorProfilerCallback::ObjectsAllocatedByClass
looks handy. Basically what I would be interested in is tracking
object allocations and garbage collections over time to see if there
are any object leaks. Not sure if it can do the garbage collections
part of that though...



Look at for more details
( http://msdn.microsoft.com/msdnmag/issues/01/12/hood/ )
( http://www.blong.com/Conferences/DCon2003/Internals/Profiling.htm )

Or if you want to know the instances number of your custom type, then
you can create objects factory, where necessary count tracking will be
implemented...

Yeah, done that in the past but it's too invasive for my liking.
 
Hello, Philip!

PD> Had a quick look, and ICorProfilerCallback::ObjectsAllocatedByClass
PD> looks handy. Basically what I would be interested in is tracking
PD> object allocations and garbage collections over time to see if there
PD> are any object leaks. Not sure if it can do the garbage collections
PD> part of that though...

ClrProfiler is doing that. Source code of ClrProfiler is available, you can
dig in there and try to find out how it tracks gc collecitons...

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Back
Top