The Disposing
flag is not a field which says whether the disposal has started for the class, but should instead be regarded as a dummy parameter to which the value true
should be passed when the protected virtual
method is called from the parameterless Dispose
method which implements the interface. The parameter was originally designed so as to allow a common "patch point" for derived classes which want to add functionality to both Dispose
and Finalize
(destructor) methods, but in practice it's almost never appropriate for a derived or unsealed class to implement Finalize
code unless the class is derived directly from Object
or from a class whose whole purpose centers around such cleanup.
Note that unlike most interfaces, the IDisposable
"contract" doesn't impose any obligations on the class which implements it, but instead exists as a standard means via which many types of classes can impose certain transferable contractual obligations on code which requests their construction. A typical IDisposable
object will ask some other entity to do something on its behalf until further notice, will promise that other entity that it will be informed when its services are no longer required, and will use its Dispose
method for the purpose of giving such notice. The constructor contract for many classes which implement IDisposable
will require that the caller either ensure that before it abandons the object it will either Dispose
it or give it to some other entity that promises to do so.