Re: IDisposable or not in custom classes



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



.



Relevant Pages

  • Re: IDisposable or not in custom classes
    ... canonical rules for IDisposable implementation. ... their custom classes inherit IDisposable or not as a general rule, ... any good reason not to make every custom class IDisposable, ... and would it simply be enough to destroy references to them by ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Controlling Javascript from server side
    ... but five different language implementations here. ... 'true' means that the request must be handled asynchronously. ... There is exactly *no* reason for such a thing here. ... | percent-endoded string). ...
    (comp.lang.javascript)
  • Re: Controlling Javascript from server side
    ... being the default HTTP charset ever since. ... No, it does not, as the specification and the implementations differ here. ... I said that for a good reason. ... 'true' means that the request must be handled asynchronously. ...
    (comp.lang.javascript)
  • Re: OT: sea level rise hmmmmm....
    ... what I do when there is a request I don't have time to ... publications, and with what I believe good reason, but right now I won't. ... of providing an informed digest. ... paper that later just _happens_ to have some policy impact doesn't ...
    (sci.electronics.design)
  • Re: [PHP] Looking for a reasonable explanation as to why $_REQUEST exists
    ... have a session variable they want to access and use $_REQUEST for it I ... I see no reason why people would not want to clearly ... superglobals before I really understood how important they were and ... So whether id comes from get or post doesn't matter ...
    (php.general)