Hi all.
I'm working currently with TAdvStringGrid and dealing with some memory leaks that I was not expecting.
The code is this:
procedure ThkDialogmeldingerForm.ShowSortingCol();
var
nCol: integer;
grd: TAdvStringGrid;
begin
nCol := -1;
grd := grdData;
if FSortColumn <> '' then
begin
nCol := GetColumnIndexByName(FSortColumn);
if nCol > -1 then
begin
for var x: integer := 0 to grd.ColCount -1 do
begin
if not grd.IsHiddenColumn(x) then
begin
if x = nCol then
grd.FontStyles[x,0] := grd.FontStyles[x,0] + [fsBold]
else
grd.FontStyles[x,0] := grd.FontStyles[x,0] - [fsBold];
end;
end;
end;
end;
end;
This is called each type the user clicks on the column header, so it should show the sorting column.
Either I run this once or a bunch of times, I always find the same exact memory leak, as following:
![image](https://support.tmssoftware.com/uploads/default/original/2X/4/476e9e9069ae2f3c89ce738e38850b4bb29cab36.png)
I used madExcept to track the exception and I received this:
Can anyone help me out?
I'm using the most up-to-date components.
Many thanks to all.
I could not reproduce this with a default grid on the form and the code:
procedure TForm1.Button1Click(Sender: TObject);
var
x: integer;
r: integer;
begin
r := random(advstringgrid1.ColCount);
for x := 0 to advstringgrid1.ColCount -1 do
begin
if x = r then
advstringgrid1.FontStyles[x,0] := advstringgrid1.FontStyles[x,0] + [fsitalic]
else
advstringgrid1.FontStyles[x,0] := advstringgrid1.FontStyles[x,0] - [fsItalic];
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
advstringgrid1.LinearFill(true);
ReportMemoryLeaksOnShutdown := true;
end;
Many thanks for the extremely fast answer.
In my grid, many columns are hidden.
I found, in another part of the code, that if I set cell properties in hidden columns/cells, I receive memory leaks of the type TCellProperty.
For example, if I use grdData.RowFontColor[row] := fontColor, I get a memory leak.
If I use the following code, instead:
var r: TGridRect;
var fontColor: TColor := TStyleManager.ActiveStyle.GetSystemColor(clGrayText);
r.Left := 1;
r.Right := 9;
r.Top := row;
r.Bottom := row;
grdData.SetCellTextColor(r, fontColor);
the memory leak do not happen, and the UI result is the same. Notice that the columns until the 9th are visible. After that, the columns are hidden.
It might happen that if I use the same approach, I get rid of the mem leak.
Lets hope for that.
Thanks again for the help.
well... the use of a TGridRect and the SetRowTextStyle do not work as expected as well, since I got the same memory leak.
The funny thing is that either I run it once or more times, the leak is always the same. If I close the form and call it again, the mem leak will be duplicated and so on.
I thought it could be something else, but commenting the code for this and the leak is gone.
Is my snapshot of the madExcept stack any good to bring some light on the matter?
Thanks a million.
Artur
Retested with:
procedure TForm1.Button1Click(Sender: TObject);
var
x: integer;
r: integer;
begin
r := random(advstringgrid1.ColCount);
for x := 0 to advstringgrid1.ColCount -1 do
begin
if x = r then
advstringgrid1.FontStyles[x,0] := advstringgrid1.FontStyles[x,0] + [fsitalic]
else
advstringgrid1.FontStyles[x,0] := advstringgrid1.FontStyles[x,0] - [fsItalic];
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
advstringgrid1.ColCount := 10;
advstringgrid1.LinearFill(true);
advstringgrid1.HideColumn(1);
advstringgrid1.HideColumn(7);
advstringgrid1.HideColumn(8);
advstringgrid1.HideColumn(9);
ReportMemoryLeaksOnShutdown := true;
end;
No memory leak.
Well... what can I say?
For sure something is messing up with this, and I do not know why.
If I comment the code, I do not have any leaks. If I uncomment the code, I have those leaks.
Could it be because the grid is inside an Update state? Started with BeginUpdate and it is ended with a EndUpdate call. I'll test it later.
For now, I'll let it be this way. There are only some bytes leaking. I have to move forward and I'll catch this later.
Many thanks Bruno, by your kind attention.
Regards,
Artur
BTW, what is that LinearFill used for?
Is there any updated manual that I could have? I found that the available on your site/setup is lacking a bunch of new things, and it's hard to reach on how they work.
Thanks again.
Artur
The most efficient is to try to isolate this and send a sample source project with which we can reproduce the problem here.
1 Like
Thanks Bruno.
I'll get to this later, I believe.
I'll try to isolate the units and make it run, with no DB and all the rest.
For sure I'm doing anything wrongly.
My best regards,
Artur