views:

10

answers:

1

Hi Guys,

Please can any one advise me if there is an object in .net that can be used to get a list or references to all objects that are currently in scope for an object. For example if the code is currently executing in a method, what objects declared in this method are currently instanciated and alive and what objects that are declared at class level have been instanciated already and are alive?

Also I know I can test each object declared explicitly for a null reference, but I am looking for something that is more generic (perhaps using reflection?) that can be used from any method to clear up all alive objects.

Thanks in advance,

Best regards,
Duane.

A: 

I don’t think this information can be retrieved. If it were available, it would probably be available through the System.GC class – but it isn’t.

Reflection can only get you so far – you can inspect objects and with a bit of trickery even local declarations in methods, but you’ve got no easy way of knowing which contexts are active. A stack trace can yield the required information for the (current thread’s) call stack, but this will ignore all static variables in the current application domain (and the System.AppDomain class doesn’t allow access to this information either).

Konrad Rudolph
Ok thanks guys. Had to ask! :o)
Dib