TAdvStringGrid Memory-Leak on use of FontColors

I get a memory leak when this procedure/ButtonClick is used twice.

procedure TMainForm.btn_PressTwiceClick(Sender: TObject);
var i: Integer;
begin
  Asg.RowCount:=2; Asg.ColCount:=2;
  Asg.FixedCols:=1;
  Asg.Cells[0,0]:= 'Col0';
  Asg.Cells[1,0]:= 'Col1';
  For i := 0 to 5 do
   begin
     asg.AddRow;
     asg.cells[0, asg.LastRow] := 'AnyText';
     asg.Floats[1,asg.LastRow] := 3.14;
     asg.FontColors[asg.LastCol, asg.LastRow] := clRed;
   end;
end;

Minimal Test-Project to reproduce: asg_fontcolors.zip (76.6 KB)

That is expected.
When you just change .RowCount while there are still rows holding objects, these objects are not auto released. Call grid.Clear before if you want to do this.

Thanks - this works as expected. I thought that I only need to clear, when I bind own objects to the grid or cells. Did not expect that this is needed for "internals" like fontcolor also. I expected that the grid cleans its "own" object self. Is this needed for other properties of cells (eg. font.size or font.name or brush.color) also ? I never did that...

As soon as something more than the cell text is used, an internal cell object is created.
It is cleaned up when you do grid.RemoveRow(s) but not when you directly manipulate grid.RowCount. As this way with grid.RowCount is often used to temporarily hide/unhide rows and then you would lose the cell objects unwanted.

Fine - understood !

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.