Re: problem with freeing Tlist

Posted by William on January 05, 2007

In Reply to problem with freeing Tlist posted by Reynir Svavarsson on September 12, 2006

: when I read value out of the database that is access in this case, Tlist canīt be freed of memory, and when I press this button many times to update list, the memory grow big time until out of mem.. But when I just use string instead of reading from database, everything works OK.
:
: procedure TForm1.Button4Click(Sender: TObject);
: var
: song:Ttest;
: I:integer;
: artist :string;
: begin
: songlist.free;
: songlist := Tlist.Create;
: for i := 0 to 500000 do begin
: song := Ttest.create;
: //song.name := 'artist';
: song.name := ADOQsongs2.FieldValues['artist'];
: songlist.add(song);
: song.free;
: end;
: end;

You write that using the string 'artist' doesn't give you the problems, but I'm sure that if you would test it with a longer string or with more than 500000 cycles, you would also see memory problems. That's because *before* freeing a TList, you have to free the objects where this TList is pointing to.

Source code example:

if Songlist.Items.Count > 0 then begin
  for i := 0 to Songlist.Items.Count - 1 do
    (Songlist.Items[i] as TTest).Free;
end;
Songlist.free;


Related articles

       

Follow Ups