Re: About speed
- From: Barry Kelly <barry.j.kelly@xxxxxxxxx>
- Date: Mon, 26 Jun 2006 10:35:21 +0100
"Ingvar Nilsen" <no.spam@xxxxxxxxxxxxx> wrote:
Barry Kelly wrote:
protected virtual void Dispose(bool disposing)
In what case would this be called with disposing = false?
So the short answer is never, unless a descendant implements a
finalizer.
"disposing" is true iff Dispose(bool) was called explicitly via
Dispose(), Close(), IDisposable.Dispose() or some other explicit
resource disposal method. An explicit resource disposal means one can
safely dispose one's owned resources.
"disposing" is false iff it was called by overriding the Finalize()
method (the way you override Finalize() in C# is by implementing ~T()
for a type T). Being called by the finalizer implies being called on the
finalizer thread after being collected by the GC, so accessing other
managed classes may not work - they might be finalized already, they
might not, or the field might be nulled out - basically, don't do it.
I'm not sure exactly what happens because I've never done it myself :)
The pattern I posted, which consists of IDisposable and the protected
virtual void Dispose(bool) alone, doesn't implement a finalizer, so it
won't get called with disposing == false *unless* a descendant class,
which does encapsulate an unmanaged resource directly, implements a
finalizer.
I'd like to point anyone who's got more interest in the topic to:
http://www.bluebytesoftware.com/blog/PermaLink.aspx?guid=88e62cdf-5919-4ac7-bc33-20c06ae539ae
-- Barry
--
http://barrkel.blogspot.com/
.
- Follow-Ups:
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- References:
- Re: About speed
- From: Craig Stuntz [TeamB]
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Robert Giesecke
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: Barry Kelly
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- Prev by Date: Re: About speed
- Next by Date: Re: Nostalgic review of Borland tools
- Previous by thread: Re: About speed
- Next by thread: Re: About speed
- Index(es):
Relevant Pages
|