Wait...
This article says "When implementing the dispose pattern you might also add a finalizer to your class that calls Dispose(). This is to make sure that Dispose() always gets called, even if a client forgets to call it. "
Maybe this is the missing piece of information that I have been failing to understand. Is this correct? On the face of it I would think that it's totally incorrect. Here's why I would think that...
The finalizer is the last method anything will call on an object before it is garbage collected. In order for this to occur, the object must have no other references pointing to it from other objects that have not been garbage collected. So, what's the point of calling Dispose from within the Finalizer? Presumably, if the GC is calling the finalizer, it's because the object has already been disposed and lost all of its references to other objects.
No comments:
Post a Comment