If the finalizer of that class calls Dispose()
, yes. If not, no.
(edit) Just some additional info:
Do not assume that Dispose will be
called. Unmanaged resources owned by a
type should also be released in a
Finalize method in the event that
Dispose is not called.
Edit
To clarify the above edit, I have seen many people (in this thread, on SO, and elsewhere) claim that "The GC will call Dispose()
when the object is removed." This is not the case at all. Yes, a good, defensive coder writing a component will assume that Dispose()
won't be called explicitly and does so in the finalizer. However, a good, defensive coder USING a component must assume that the finalizer does NOT call Dispose()
. There is no automatic calling of Dispose()
in the garbage collector. This functionality is ONLY in place if the finalizer calls Dispose()
.