🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: IDisposable - When?

#662
From: Joe Mayo
Date: Fri, 17 Sep 2004 13:28
82 lines
3292 bytes
Hi Theo,

If you don't have any unmanaged resources in your type, there really isn't a
reason to use IDisposable.  This is not the same as garbage collection (GC).
With IDisposable you want to release unmanaged resources, such as file
streams or db connections because they are a limited resource.  On the other
hand, garbage collection is a process for releasing memory resources for
objects that are no longer referenced.  So, you can call Dispose on an
object and release the unmanaged resources, but the object itself is still
in memory until (1) there are no more references to it and (2) the GC runs.
In the majority of cases, it is best to just let the GC clean up memory for
objects and only implement IDisposable on types that have to release
unmanaged resources.

Joe
-- 
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com



"Theo Bebekis" <teo@thinx.gr> wrote in message
news:414ac1ca@newsgroups.borland.com...
> Hi there
>
> Well, after reading the relevant topics the online help provides,
> I'm still consfused. When do I have to implement IDisposable?
>
> Please, see the following imaginery scenario.
>
>    public class Room {}
>
>    public class RoomList
>    {
>     // contains a list of rooms
>    }
>
>    public class House
>    {
>     public RoomList Rooms = new RoomList();
>    }
>
>    public class HouseList
>    {
>     // contains a list of houses
>    }
>
>    public class Quarter
>    {
>     public HouseList Houses = new HouseList();
>    }
>
>
> None of the above classes contains/uses unmanaged resources.
> What I want is when a Quarter is disposed all the contained objects
disposed.
> Do I have to implement IDisposable and where?
> Should I stop worrying and let GC do the job, when just managed resources
> are involved?
>
> Implementing the above hierarchy in Delphi (<=7) seems so easy to me.
> Just a couple of TLists or -better- TObjectLists and done.
> Now what?
>
> I have to admit it anyway: I miss TObjectList and TStringList.
>
> -- 
> Regards
> Theo
>
> PS. God, I love this job. It keeps me young. ( lol )
>
> ------------------------
> Theo Bebekis
> Thessaloniki, Greece
> ------------------------
> Greek_Delphi_Prog
> A Delphi Programming mailing list in Greek
> http://groups.yahoo.com/group/Greek_Delphi_Prog
> ------------------------
Technical Details
Message-ID: <414ae664@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <414ac1ca@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,b3e8021b863a6f6b
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Joe Mayo" <jmayo@nospam.mayosoftware.com>
Newsgroups: borland.public.csharpbuilder.language.csharp
References: <414ac1ca@newsgroups.borland.com>
Subject: Re: IDisposable - When?
Date: Fri, 17 Sep 2004 07:28:15 -0600
Lines: 84
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 67.176.104.159
Message-ID: <414ae664@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1095427684 67.176.104.159 (17 Sep 2004 06:28:04 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail