IDisposable is an interface implemented by all types which need to
provide a mechanism for releasing unmanaged
resources.
Unlike managed memory, which is taken care of by the garbage collection,
The interface declares a Dispose method, which the
implementer has to define.
The method name Dispose
should be used exclusively to implement IDisposable.Dispose
to prevent any confusion.
It may be tempting to create a Dispose
method for other purposes, but doing so will result in confusion and likely lead to problems in
production.
Exceptions
Methods named Dispose
and invoked from the IDisposable.Dispose
implementation are not reported.
public class GarbageDisposal : IDisposable
{
protected virtual void Dispose(bool disposing)
{
//...
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}