🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.csharpbuilder.oodesign
3 messages
3 total messages Started by Theo Bebekis Fri, 17 Sep 2004 11:47
IDisposable - When?
#54
Author: Theo Bebekis
Date: Fri, 17 Sep 2004 11:47
56 lines
2239 bytes
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
------------------------
Re: IDisposable - When?
#55
Author: Angel
Date: Fri, 17 Sep 2004 17:20
78 lines
3136 bytes
You should not worry about freeing those objects.
In your scenario GC will take care of releasing the memory and will do this 
for all unreachable objects.
(Objects to for which there is no reference in the scope)
And if they are objects you cannot reach you shouldn't care when exactly 
they will be released anyway.
All you need to know is that at some point in time GC will release their 
memory.

About TObjectList and TStringList just use ArrayList it has almost the same 
functionality as TStringList.
Strings are objects in C# so it should work fine for the strings as well.
If you need "Name=Value" functionality of TStringList you can use some class 
derived from
   System.Collections.DictionaryBase

Angel


"Theo Bebekis" <teo@thinx.gr> wrote in message 
news:414ace2a$1@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
> ------------------------ 
Re: IDisposable - When?
#56
Author: Marc Rohloff TeamB
Date: Mon, 20 Sep 2004 12:27
9 lines
1032 bytes
On Fri, 17 Sep 2004 14:47:19 +0300, Theo Bebekis wrote:

> Hi there

Theo, please don't multipost.

-- 
Marc Rohloff [TeamB]
marc rohloff at myrealbox dot com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads