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—unused references will still remain in memory until the garbage collector kicks in, which is not a good idea. A better approach is to provide 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
method. Implementing ...
Get Visual Basic 2015 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.