🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #297

Re: IDisposable.Dispose()

#297
From: Marc Rohloff TeamB
Date: Wed, 25 Jan 2006 23:14
27 lines
2366 bytes
On Wed, 25 Jan 2006 14:30:54 -0700, Steve wrote:

> If you instantiate a class that implements IDisposable, then should you
> call .Dispose() on it?  Must you?  Should you not?

> It seems from MSDN that I should .Dispose(), but I am not sure.  Some
> developers I talk to say, "No."

I would ask them why they say "No", or even as them "Why not?".

The GC will *eventually* clean-up the resources for you (assuming that
IDisposable has been implemented properly).
Firstly, 'eventually' can turn out to be quite a long time, and , say
in the case of databases which are licensed per connection, that might
be important.
Secondly, there are exceptions to this. You can't cleanup resources
which have a thread affinity from GC because the GC may or may not be
running in a different thread. So often resources aren't properly
deallocated in the Finalizer.

The bottom line is that, unless you know that your object hasn't
allocated any resources (hard to tell), you should call Dispose or use
the 'with' syntax.

-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Technical Details
Message-ID: <b8t1e8hhiv2v$.dlg@marcrohloff.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!195.92.193.196.MISMATCH!nntp.theplanet.net!inewsm1.nntp.theplanet.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43D7EE0E.22B25762@nospam.crowneone.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,812df04fa7082d34
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Marc Rohloff [TeamB]" <"on request">
Subject: Re: IDisposable.Dispose()
Newsgroups: borland.public.csharpbuilder.language.csharp
User-Agent: 40tude_Dialog/2.0.15.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
References: <43D7EE0E.22B25762@nospam.crowneone.com>
Date: Wed, 25 Jan 2006 18:14:31 -0500
Message-ID: <b8t1e8hhiv2v$.dlg@marcrohloff.com>
X-Face: "huzh55Xi]!ZNni78>a*5+).`SK?<^q2MlHk-C]Z2M9T@\J5ZCB$95Ey+s"XQuhGFA[eutZ :0^AV!Q;t>gE`1-=8d;HZ6~*o1dH<X9\b$!|(}+I'!Xq)@3Op}%0ArW&nf'Qh*EwR
X-Antivirus: avast! (VPS 0604-2, 01/25/2006), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 65.31.14.220
X-Trace: newsgroups.borland.com 1138230556 65.31.14.220 (25 Jan 2006 15:09:16 -0700)
Lines: 27
X-Authenticated-User: mrohloff
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!195.92.193.196.MISMATCH!nntp.theplanet.net!inewsm1.nntp.theplanet.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail