I'm trying to make sure that my understanding of IDisposable
is correct and there's something I'm still not quite sure on.
IDisposable
seems to serve two purpose.
- To provide a convention to "shut down" a managed object on demand.
- To provide a convention to free "unmanaged resources" held by a managed object.
My confusion comes from identifying which scenarios have "unmanaged resources" in play.
Say you are using a Microsoft-supplied IDisposable
-implementing (managed) class (say, database or socket-related).
- How do you know whether it is implementing
IDisposable
for just 1 or 1&2 above? - Are you responsible for making sure that unmanaged resources it may or may not hold internally are freed? Should you be adding a finalizer (would that be the right mechanism?) to your own class that calls instanceOfMsSuppliedClass.Dispose()?