IDisposable.Dispose

Dispose methods complement finalizers. Contrary to finalizers, Dispose methods are deterministic and can access managed types. Dispose methods are sometimes referred to as explicit garbage collection. You can call Dispose for immediate cleanup of resources associated with an object, such as closing a file handle. Remember that accessing a managed object in a finalizer is inadvisable. This requirement greatly limits the flexibility and functionality of a finalizer. The Dispose method does not have this limitation because garbage collection is not occurring simultaneously.

The Dispose method is defined in the IDisposable interface, which is found in the System namespace. Disposable objects should inherit and implement the IDisposable ...

Get Programming Microsoft® Visual C#® 2008: The Language now with O’Reilly online learning.

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