Board index » delphi » TList's remove/delete?

TList's remove/delete?

Hi!

Just wondering:

When using a TList object, does the methods named Delete and
Remove deallocate memory? Or do they only remove the item from
the list?

I really need to know, so if you have ANY idea or hint -
please let me know!

Thanks,
Cristian

 

Re:TList's remove/delete?


Quote
Anders Olsson wrote:

> Hi!

> Just wondering:

> When using a TList object, does the methods named Delete and
> Remove deallocate memory? Or do they only remove the item from
> the list?

> I really need to know, so if you have ANY idea or hint -
> please let me know!

> Thanks,
> Cristian

TList simply removes the object from the list without deallocating or
destroying the object. You have to take care of disposing the object
yourself. If you may have used the old BP7 TCollection, which does
dispose of objects properly.

There is a TListCollection class that was provided in "Delphi
Developer's Guide" by Xavier Pacheco & Steve Teixeira from Borland
Press. This is a nice replacement for TList that does dispose of objects
properly. I am using it to store a list of TStrings with good results.

I do not believe I can post the TListCollection code here due to
copyright restrictions. But the book is well worth the investment.

Cheers
Ramesh

Re:TList's remove/delete?


Quote
christian.almstr...@elektro.ing.hb.se (Anders Olsson) wrote:
>Hi!

>Just wondering:

>When using a TList object, does the methods named Delete and
>Remove deallocate memory? Or do they only remove the item from
>the list?

>I really need to know, so if you have ANY idea or hint -
>please let me know!

>Thanks,
>Cristian

To reallocate all the memory, quickly, used by the objects contained
in a TList object:

      AList.Clear;
then
      AList.Free;

The Clear method removes all the pointers and reallocates memory, and Free
frees the memory used by the List object.

Remove/Delete only removes/deletes the object contained at a position
within the list object and the position is set to NIL.

--
                        John Sylvestre
                       Montreal, Quebec
                            Canada
******************************************************************
To err is human, but to really foul things up requires a computer.
Anonymous. Quoted in: "Quote Unquote," 22 Feb. 1982, BBC Radio 4
******************************************************************

Re:TList's remove/delete?


On 31 Dec 1995 13:08:13 GMT, John Sylvestre

Quote
<john.sylves...@sympatico.ca> wrote:
>>When using a TList object, does the methods named Delete and
>>Remove deallocate memory? Or do they only remove the item from
>>the list?

>To reallocate all the memory, quickly, used by the objects contained
>in a TList object:

>      AList.Clear;
>then
>      AList.Free;

>The Clear method removes all the pointers and reallocates memory, and Free
>frees the memory used by the List object.

Clear and Free affect only the list itself, not what the list items
point to.

Quote
>Remove/Delete only removes/deletes the object contained at a position
>within the list object and the position is set to NIL.

Contrary to Borland's documentation, Remove and Delete do not set the
position to nil. They really delete the item from the list (without
freeing any memory).
--
Ray Lischner         (li...@tempest-sw.com)
Tempest Software, Corvallis, Oregon, USA

Other Threads