Re: IDisposable or not in custom classes
- From: "Dave Sexton" <dave@jwa[remove.this]online.com>
- Date: Wed, 13 Dec 2006 19:34:21 -0500
Hi Mark,
There are very specific guidelines in place for when to implement
IDisposable.
Are there? Are they available for download anywhere...?
".NET Framework Developer's Guide, Implementing Finalize and Dispose to
Clean Up Unmanaged Resources"
http://msdn2.microsoft.com/en-us/library/b1yfkh5e.aspx
".NET Framework Developer's Guide, Implementing a Dispose Method"
http://msdn2.microsoft.com/en-us/library/fs2xkftw.aspx
Check out the TOC on the left and you'll see a whole bunch of topics that
provide development guidelines for many other things.
Note that the guidelines recommending to use Dispose along with a finalizer
can be accomplished easily by deriving your class from Component, which
provides the recommended behavior already; however, that certainly doesn't
mean you should derive all of your classes from Component just like you
shouldn't implement IDisposable on all of your classes either. Deriving
from Component also provides base designer support for your business objects
so they can be added to the component tray from the toolbox, a protected
EventHandlerList used by derived Controls, and a Container/Site pattern
implementation for designers, which may be useful to you in and of itself.
Realize too that you don't need to have a finalizer on your classes (that
don't derive from Component) if they simply aggregate or composite
references to IDisposables since each IDisposable reference should have
already implemented their own finalization code to release the unmanaged
resources.
--
Dave Sexton
"Mark Rae" <mark@xxxxxxxxxxxxxxxxx> wrote in message
news:Ol1O3puHHHA.1280@xxxxxxxxxxxxxxxxxxxxxxx
"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:%23T6DsguHHHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
Nicholas,
Can you show the thread that you are referring to?
Its subject is "HttpWebRequest and IDisposable" and it was started by me
in this group on 10th December.
I don't know if it was pointed out, but there is no reason to implement
IDisposable on the request since the request doesn't do anything until it
is sent.
It's actually not possible to implement it because it's not disposable,
much to everyone's surprise...
And yes, it is overkill to implement it on all the classes.
Indeed.
There are very specific guidelines in place for when to implement
IDisposable.
Are there? Are they available for download anywhere...?
Mark
.
- Follow-Ups:
- Re: IDisposable or not in custom classes
- From: Mark Rae
- Re: IDisposable or not in custom classes
- References:
- IDisposable or not in custom classes
- From: Mark Rae
- Re: IDisposable or not in custom classes
- From: Nicholas Paldino [.NET/C# MVP]
- Re: IDisposable or not in custom classes
- From: Mark Rae
- IDisposable or not in custom classes
- Prev by Date: Re: Is file is being used
- Next by Date: Re: Dynamically creating form controls
- Previous by thread: Re: IDisposable or not in custom classes
- Next by thread: Re: IDisposable or not in custom classes
- Index(es):
Relevant Pages
|