AddRow & Out of memory

If I use the procedure AddRow gradually to 33,000 lines or more (irregularly), appears error Out of memory. If I set at the beginning of the line (RowCount) on the number of lines and then I follow, it's ok.

For performance, it is far better to use:

grid.RowCount := grid.RowCount + 33000 rather than 33000 calls to AddRow.
Other than this, I tested this here with:
var
  i: integer;
begin
  for i := 0 to 50000 do
    begin
      advstringgrid1.AddRow;
    end;
end;
and this is working without any issue here.

Your solution is ok. Thanx.



For example my code:



mRS is any DataTable structure

mAG is TAdvStringGrid



    while not mRS.EOF do begin

      if not mFirstRow then

        mAG.AddRow // --->> I replaced mAG.RowCount := mAG.RowCount + 1

      else

        mFirstRow := False;

      mRow := mAG.RowCount-1;



      for i:=0 to mRS.FieldCount-1 do

        case VarType(mRS.Data.Item) of

          varString, varOleStr: begin

            mAG.Cells[mAG.ColumnByHeader(mRS.Fields.Name), mRow] := Trim(mRS.Data.Item);

            mAG.Objects[mAG.ColumnByHeader(mRS.Fields.Name), mRow] := TObject(1);

          end;

          varInteger, varByte, varSmallint, varShortInt: begin

            mAG.Ints[mAG.ColumnByHeader(mRS.Fields.Name), mRow] := mRS.Data.Item;

            mAG.CellProperties[mAG.ColumnByHeader(mRS.Fields.Name), mRow].Alignment := taRightJustify;

          end;

          varDouble, varDate, varSingle, varInt64: begin

            mAG.Floats[mAG.ColumnByHeader(mRS.Fields.Name), mRow] := mRS.Data.Item;

            mAG.CellProperties[mAG.ColumnByHeader(mRS.Fields.Name), mRow].Alignment := taRightJustify;

          end;

        end;

      mAG.CellComment[1, mRow] := TCdSQL.SQLValue(XOLE,

        'select ID from InternalDocuments where X_VS = ''' + IntToStr(mRS.Data.ValueByName['CIS_FA']) + '''', '');


      if not mObj.IsUpdate(mRow) then with mAG do begin

        AddButton(0, mRow, CellRect(0, mRow).Right - CellRect(0, mRow).Left - 2,

          CellRect(0, mRow).Bottom - CellRect(0, mRow).Top - 2, 'NOVÁ', haFull, vaFull);


        mAG.Cells[1, mRow] := 'nový ID';

      end

      else with mAG do begin

        mDN := TCdSQL.GetDocDisplayNameByID(XOLE, mAG.CellComment[1, mRow], 'InternalDocuments');

        AddButton(0, mRow, CellRect(0, mRow).Right - CellRect(0, mRow).Left - 2,

          CellRect(0, mRow).Bottom - CellRect(0, mRow).Top - 2, mDN, haFull, vaFull);


        mAG.Cells[1, mRow] := 'oprava ID';

      end;

      mRS.Next;

    end;

If many calls results in an out of memory error and one call does not then there may be a memory leak somewhere.