Search code examples
listdelphimemoryoverflowspring4d

Delphi Spring4D IList memory overflow


I am using IList from the excellent Delphi framework Spring4D by Stefan Glienke.

I have a list IList and I refill this list many times during my application is run. So, after two or three hours I have a memory overflow of my list.

This is how I populate my list:

  list := TCollections.CreateList<TVisitor>;

  for i := 0 to dataSet.RecordCount - 1 do begin
        item := TVisitor.Create ();

        item.Surname := dataSet.FieldByName ( 'firstname' ).AsString;
        item.Name := dataSet.FieldByName ( 'secondname' ).AsString;
        item.Patronymic := dataSet.FieldByName ( 'thirdname' ).AsString;
        item.CardNumber := dataSet.FieldByName ( 'cardnumber' ).AsString;

        list.Add ( item );

        dataSet.Next ();
  end;

The Clear() method doesn't free a memory, so each time I fill my list the Windows Task Manager inc memory usage of my application :(


Solution

  • Your list does not free the TVisitor instances.

    Create is like this:

    TCollections.CreateList<TVisitor>(True);