Re: IDisposable or not in custom classes
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Dec 2006 13:57:20 -0500
Mark,
Can you show the thread that you are referring to? 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. The
WebRequest model basically places the managability of the unmanaged stuff in
the Response (which you are going to get most likely because you made the
request in the first place) and then call Dispose of it there.
And yes, it is overkill to implement it on all the classes. There are
very specific guidelines in place for when to implement IDisposable.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Mark Rae" <mark@xxxxxxxxxxxxxxxxx> wrote in message
news:eqmaeEtHHHA.1240@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
Following on from the recent thread about why HttpWebRequest doesn't
implement the IDisposable interface, I got to wondering whether people
make their custom classes inherit IDisposable or not as a general rule, or
only under certain circumstances...
Since it's an easy enough thing to do
(http://msdn2.microsoft.com/en-us/library/system.idisposable.aspx), is
there any good reason not to make every custom class IDisposable, the same
way as there's no good reason not to use exception handling in every
method...?
I can understand the rationale for implementing IDisposable for classes
which e.g. use unmanaged resources, or which open files and/or streams,
because the GC won't know about them, but what about for classes which use
/ reference only managed code? Would it be overkill to make those classes
IDisposable, and would it simply be enough to destroy references to them
by variables which have instantiated them to null...?
Interested to know your opinions...
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
- IDisposable or not in custom classes
- Prev by Date: Re: Upgrading from Framework 1.0 to 2.0
- Next by Date: Re: Please help asap.
- Previous by thread: Re: IDisposable or not in custom classes
- Next by thread: Re: IDisposable or not in custom classes
- Index(es):
Relevant Pages
|