Re:Deleting TList objects from TList (D1)
On Fri, 30 May 1997 10:44:39 -0700, Timo Romppanen
Quote
<timo.romppa...@upm10.upm-kymmene.com> wrote:
>I wonder what happens if TList has other TList objects as its
>items and an item is deleted? Is TList which is under
>other TList freed? How about when whole TList is freed?
>For example
>var
> mainlist: TList;
> itemlist: TList;
>begin
> itemlist.Create;
> itemlist.Add(...)
> mainlist.Add(itemlist);
> itemlist.Create;
> itemlist.Add(...)
> mainlist.Add(itemlist);
> mainlist.Delete(0);
> mainlist.Free;
>end;
A TList is just a list of pointers, and it does not delete the objects
in each item when it is deleted.
In your example you will have a memory leak. What you could do is making
a descendant of TList that frees its items upon destruction and use it
for both the mainlist and the itemlists.
Geir
--
Geir Tutturen
geir.tuttu...@itf.nlh.no
(use this address (the return address is a spam avoiding fake))