IDispose
-
Any object that holds on to things that need to be cleaned up will impliment IDisposable, and you should call the Dispose method on such items when you're finished with them. Common examples would include pretty much anything in the System.Drawing namespaces, or anything else that holds an unmanaged handle of some sort. We have this interface because a garbage collected system cannot support deterministic destruction. Christian Graus - Microsoft MVP - C++
-
To add to what Christian said I would also recomment that you use using{} when you use an object that implements the IDisposable interface and it will naturally go out of scope at the end of the method. For example:
using(SomeDisposableClass disposableInstance = new SomeDisposableClass())
{
// Do stuff with the disposableInstance
}When the using block is completed the Dispose() method will be called. It will also clean up the object if an exception is causing the stack to unwind.
My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
-
To add to what Christian said I would also recomment that you use using{} when you use an object that implements the IDisposable interface and it will naturally go out of scope at the end of the method. For example:
using(SomeDisposableClass disposableInstance = new SomeDisposableClass())
{
// Do stuff with the disposableInstance
}When the using block is completed the Dispose() method will be called. It will also clean up the object if an exception is causing the stack to unwind.
My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
That's if he's using C#, I don't believe VB.NET supports it. Christian Graus - Microsoft MVP - C++
-
That's if he's using C#, I don't believe VB.NET supports it. Christian Graus - Microsoft MVP - C++