14.5. Implement a Disposable Class


You need to create a class that references unmanaged resources and provide a mechanism for users of the class to free those unmanaged resources deterministically.


Implement the System.IDisposable interface, and release the unmanaged resources when client code calls the IDisposable.Dispose method.

How It Works

An unreferenced object continues to exist on the managed heap and consume resources until the garbage collector releases the object and reclaims the resources. The garbage collector will automatically free managed resources (such as memory), but it will not free unmanaged resources (such as file handles and database connections) referenced by managed objects. If an object contains data ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.