JD
Thu May 06 18:32:32 CDT 2004
The dataview is the only class that I have seen that "kind of" does the
close/dispose pattern. It inherits the MarshalByValueComponent that does
have a finalize method and implements the IDisposable interface. But if you
look in the dataview's constructor it calls GC.SuppressFinalize since it
doesn't have any unmanaged resources, so there is no need to override the
dispose method. But it does override the dispose method which calls the
close method which does some unregistering of events from the datatable.
Actually if you look at the dataview, it implements an interesting pattern
with the datatable in question, its member dvListener (type of
dataviewlistener), the dataview itself, and weak references. I haven't been
able to study the whole pattern but it looks like even if the dataview's
dispose/close method isn't called, the dataview will still be GC'd because
the dvlistener actually registers to the datatables events and the
dvlistener has a weak reference back to the dataview to communicate the
events. Like I said I haven't looked at the whole pattern but it looks like
the dvListener will still be around registered to the datatable's events and
would still hang around but the dataview will be GC'd.
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b04c83673458e2698a871@msnews.microsoft.com...
> Chad Z. Hower aka Kudzu <cpub@hower.org> wrote:
> > Jon Skeet [C# MVP] <skeet@pobox.com> wrote in
> > news:MPG.1b04418d397844b498a868@msnews.microsoft.com:
> > > I disagree - in every case I can think of which I've come across,
> > > Dispose releases the resources that the finalizer would other do.
> >
> > It depends on how the resources are used and if the Dispose is a "Close"
or
> > not. But I guess in most cases it would be the same - but not all.
>
> Possibly not all, although I'd be interested to hear of an example.
> Have you heard of any?
>
> > > Why would you *want* to wait until the object is finalized before
> > > releasing resources if you've been explicitly told that the object
will
> > > no longer be used?
> >
> > In some cases the Dispose is more of a "Close" and shares code. But I
guess
> > that if it left resources too - that wouldnt be a commonly needed
situation.
>
> Indeed - and the fact that I can't think of a single situation where
> it's the case is fairly telling, I think.
>
> Certainly I believe that your statement that "This is not the case in
> most instances" (with regard to Dispose calling SuppressFinalize) in
> untrue. (The docs for Dispose even state: "However, once the Dispose
> method has been called, it is typically unnecessary for the garbage
> collector to call the disposed object's finalizer.")
>
> --
> Jon Skeet - <skeet@pobox.com>
>
http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too