Understanding Dispose and the IDisposable Interface

One of the issues of the Finalize destructor is that you cannot determine whether resources will be freed up and when an object will be physically destroyed from memory. This is because of the nondeterministic nature of the garbage collector, meaning that unused references will still remain in memory until the GC kicks in, and generally this is not a good idea. It is instead a good approach providing clients the ability to immediately release resources (such as network connections, data connections, or system resources) just before the object is destroyed setting it to Nothing. The .NET Framework provides a way for releasing resources immediately and under your control, which is the Dispose ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.