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 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.