About Dispose method
-
I don't quite understand what dispose method exacly does. From manual I read that it "frees up ny ressources being used". But what happens to the object after calling dispose method ? Is it destroyer ? Also - is there any link between an object's destructor and dispose method ? Regards, Desmond
-
I don't quite understand what dispose method exacly does. From manual I read that it "frees up ny ressources being used". But what happens to the object after calling dispose method ? Is it destroyer ? Also - is there any link between an object's destructor and dispose method ? Regards, Desmond
Lately, Heath[^] provided me a very cool link about this subject: http://www.albahari.com/value%20vs%20reference%20types.html[^] I hope it helps!
Don't forget, that's
Persian Gulf
not Arabian gulf!
Murphy:
Click Here![^]
I'm thirsty like sun, more landless than wind...
-
I don't quite understand what dispose method exacly does. From manual I read that it "frees up ny ressources being used". But what happens to the object after calling dispose method ? Is it destroyer ? Also - is there any link between an object's destructor and dispose method ? Regards, Desmond
IDisposable.Dispose
(you must implementIDisposable
for this to be used correctly) is best used to free native resources (since many classes in .NET use nativeHANDLE
s). You can also use it to dispose child objects and set references tonull
. This is not a destructor, though. In fact, many times when theDispose
method cleans-up the resources, it will tell the GC to not call the destructor since there's nothing left to do (be sure you clean-up all resources before doing so, though):public void Dispose()
{
// Clean up native resources and any managed resource you might have.
GC.SuppressFinalize(this);
}For a more thorough example, see the documentation for the
GC.SuppressFinalize
method in the .NET Framework SDK.Microsoft MVP, Visual C# My Articles
-
I don't quite understand what dispose method exacly does. From manual I read that it "frees up ny ressources being used". But what happens to the object after calling dispose method ? Is it destroyer ? Also - is there any link between an object's destructor and dispose method ? Regards, Desmond