Memory leak (TCellProperties) in AdvStringGrid

I have found a situation where AdvStringGrid is leaking memory, specifically TCellProperties.

I use a procedure (vastly simplified below) to populate a grid:
(In my application, the procedure would be called multiple times with different values NewRowCount)

procedure PopulateGrid(Grid:TAdvStringGrid; NewRowCount:integer);
var RR:integer;
begin

  with Grid do
  begin

    RowCount:=NewRowCount;

    for RR := 1 to RowCount-1 do
    begin

      Objects[0,RR]:=TObject(RR);

      Cells[0,RR]:=IntToStr(RR);
      Cells[1,RR]:='This is row '+IntToStr(RR);

    end;

    QSort;  //adding this causes the memory leak

  end;

end;

In a test application, drop a AdvStringGrid on a form, set SortSettings.Column:=1, then call

PopulateGrid(AdvStringGrid1,5);
PopulateGrid(AdvStringGrid1,2);

exiting the program reports memory leaks of TCellProperties x 3 and UnicodeString x 3
(the x 3 leaks are the drop in row count from 5 to 2)

It seems that reducing the number of rows, and then performing a sort, doesn't free the TCellProperties objects. If I don't sort, the leak doesn't occur.

Using Delphi XE5 with component pack 8.5.7.0 (AdvStringGrid 8.2.9.1)



Please change your code to:

procedure PopulateGrid(Grid:TAdvStringGrid; NewRowCount:integer);
var RR:integer;
begin

  with Grid do
  begin
    Clear;

    RowCount:=NewRowCount;

    for RR := 1 to RowCount-1 do
    begin

      Objects[0,RR]:=TObject(RR);

      Cells[0,RR]:=IntToStr(RR);
      Cells[1,RR]:='This is row '+IntToStr(RR);

    end;

    QSort;  //adding this causes the memory leak
  end;
end;

Is there a better solution for this memory leak?  Using clear blows away the grid headers.

ClearNormalCells

Excellent. Thank you. :)