Dispose doesn't clean up the same resources as the GC. Its there to allow timely clean up of *non-memory* resources. The GC only cleans up memory. If an object implements IDisposable and you have ownership of the object then you should call dispose on it. You are confusing GC with finalization. Finalization is something that happens (hopefully) after the GC realizes a finalizable object is collectable.I say hopefully because it isn't guaranteed to run. You need to make your object finalizable (implement a C# destructor) if and only if you are managing non-managed resrouces like windows HANDLEs and the like. If you implement a finalizer then you should also implement IDisposable. However, there are good reasons to implement IDisposable even if you don;t imeplement a finalizere (for example you have memebers which themselves implement IDisposable).
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
"Bruce" <bv***************@mailblocks.com > a ?crit dans le message de news:
lr********************************@4ax.com...
Something like this:
void DestroyObject(ref BaseObject obj)
{
obj.Dispose();
obj = null;
}
DestroyObject(ref derivedObject1);
DestroyObject(ref derivedObject2);
DestroyObject(ref derivedObject3);
Yes, but I have to ask why you are explicitly disposing of objects instead
of letting the garbage collector do its work ? Or do your classes hold
references to Windows resources or file handles?
Joanna