Its part of the dispose pattern.
Microsoft describes the dispose pattern to look like:
public void Dispose()
{
// Dispose of unmanaged resources.
Dispose(true);
// Suppress finalization.
GC.SuppressFinalize(this);
}
To quote the link:
The Dispose
method performs all object cleanup, so the garbage collector no longer needs to call the objects' Object.Finalize
override. Therefore, the call to the SuppressFinalize
method prevents the garbage collector from running the finalizer. If the type has no finalizer, the call to GC.SuppressFinalize
has no effect. Note that the actual cleanup is performed by the Dispose(bool)
method overload.
edit:
Looking further, with regards to DRY, I would StreamWriter.Close()
just to call StreamWrite.Dispose()
. Furthermore, StreamWriter.Close()
seems redundant anyhow, as the base class TextWriter.Close()
has the same contents! (And that one should directly call TextWrite.Dispose()
.
But that's just MHO.)