class object disposal

  • Thread starter Thread starter Philip Gray
  • Start date Start date
P

Philip Gray

Hello all,

Simple one - If I have a class that invokes a series of other objects, each
calling their own objects and so on, do I have to explicity dispose of all
of the objects or can I just kill the top level class and all of the
resources will be released?

I'm aware of the resource implications of keeping a lot of objects open,
particularly on the pocketpc, but if I can do this, it'll save me quite a
bit of faffing about.

Thoughts?
 
Hi Philip,

Dispose does not work like a destructor so any time that you need to Dispose
something, you need to do so explicitly. What I typically do in this type
of situation is have the top level class implement IDisposable and then use
that Dispose to iterate through the objects and call Dispose on each one.
Obviously, you then need to make sure you call Dispose on the top level
class instance.

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top