-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak version Version 8 ARM64 bit #163
Comments
Hello @John-Smith75 I am not sure what happens here that leads to a memory leak, though looking at the code, it seems it is a dynamic array that is temporarily created. It is in principle handled by the compiler, so I presume it is a bug in the compiler, maybe for this particular CPU. One way to test it would be to check if the following code leads to a memory leak: type
TBGRAPenStyle = array Of Single;
var
FCustomPenStyle: TBGRAPenStyle;
function DuplicatePenStyle(ACustomPenStyle: array of single): TBGRAPenStyle;
var
i: Integer;
begin
setlength(result,length(ACustomPenStyle));
for i := 0 to high(result) do
result[i]:= ACustomPenStyle[i];
end;
function GetCustomPenStyle: TBGRAPenStyle;
begin
result := DuplicatePenStyle(FCustomPenStyle);
end;
procedure ComputeWidePolylinePoints(const penstyle: TBGRAPenStyle);
begin
// do stuff
end;
procedure ComputePolyline;
begin
ComputeWidePolylinePoints(GetCustomPenStyle);
end;
begin
setlength(FCustomPenStyle,2);
FCustomPenStyle[0] := 3;
FCustomPenStyle[1] := 1;
ComputePolyline;
end. By the way, does adding function DuplicatePenStyle(const ACustomPenStyle: array of single): TBGRAPenStyle; Regards |
Hi, Thank you for the reply , unfortunately I do not know how to fix it. Pitty as this is a great component. |
Hi, I invite you to try the sample code. For this, create a simple program with only the provided code. I suppose the memory leak would happen as it is the same structure of calls. Is it that you are considering to not use the component if the memory leak remain? Regards |
Hi , thanks, I will try the code. the problem is for example on a pi 4 1 GB the pi runs out of memory in +- 2 days on a 64bit OS Regards |
Hi $0000000000475D18 GETCUSTOMPENSTYLE, line 54 of unit1.pas Issue here heaptrace Regards |
I can also give you remote access to a pi using vnc |
Thank you very much for the detailed information. Ok, so this confirms the bug is in the FPC compiler. It may be related to: I've tried to reproduce the bug on my system but I didn't get the memory leak. I suggest we create the bug report together. Here is a draft below. Can you fill the system information? I noted that you tested it on a project with a form. It would be better to test it on a "simple program". It is one of the option when creating a new project. It will give you a simple file which content can be replaced completely by the sample code I've provided. This way it can be fixed by the FPC team without using Lazarus. The resulting log of Heaptrc would be slightly different. Can you provide what it produces with a simple program? Here is the link to create the issue in FPC if you feel confident to do so: IssueMemory leak with dynamic array passed as const parameter SummaryA user of my library noticed a memory leak related to a dynamic array. It is passed as const parameter and does not seem to be freed afterwards. It may be related to #40225. System Information
Steps to reproduceRun the project with heaptrc unit. Example Projecttype
TBGRAPenStyle = array Of Single;
var
FCustomPenStyle: TBGRAPenStyle;
function DuplicatePenStyle(ACustomPenStyle: array of single): TBGRAPenStyle;
var
i: Integer;
begin
setlength(result,length(ACustomPenStyle));
for i := 0 to high(result) do
result[i]:= ACustomPenStyle[i];
end;
function GetCustomPenStyle: TBGRAPenStyle;
begin
result := DuplicatePenStyle(FCustomPenStyle);
end;
procedure ComputeWidePolylinePoints(const penstyle: TBGRAPenStyle);
begin
// do stuff
end;
procedure ComputePolyline;
begin
ComputeWidePolylinePoints(GetCustomPenStyle);
end;
begin
setlength(FCustomPenStyle,2);
FCustomPenStyle[0] := 3;
FCustomPenStyle[1] := 1;
ComputePolyline;
end. What is the current bug behavior?The dynamic array created by DuplicatePenStyle is not freed. What is the expected (correct) behavior?The dynamic array is supposed to be freed. Relevant logs and/or screenshots
Possible fixesI suppose the problem happen when passing the parameter to ComputeWidePolylinePoints. |
Hi Here is the result of a normal project Call trace for block $0000007FF7FED2C0 size 8 Regards |
If you can upload a compiled binary then I can download , test it and send you the results. Best Regards |
The trace you've provided is fine, thank you very much. Now what shall I put in the System Information paragraph? Operating system: |
My pleasure and thank you FPC 3.2.2 Best Regards |
The operating system is Linux? The device is a PC? |
Yes Linux Rasbiam Bullsey . |
Ok. With all the information I was able to file the bug report: I invite you to log in the bugtracker and enable the notifications about the issue, so that you will know how it progresses. |
Thank you , appriciate it Regards |
Added one dail with a timer.
Code
DTAnalogLoad.Position:= Random (5000);
if DTAnalogLoad.Position > 3000 then
begin
DTAnalogLoad.FaceSettings.ColorEnd := Clred;
end
else
begin
DTAnalogLoad.FaceSettings.ColorEnd := ClLime;
end;
Heaptrace +- 2252 with in a 2 sec runtime
Call trace for block $0000007FA4533B80 size 0
$00000000009504A4 GETCUSTOMPENSTYLE, line 1159 of bgrapen.pas
$00000000009511D8 COMPUTEPOLYLINE, line 1288 of bgrapen.pas
$00000000008649A8 DRAWLINEANTIALIAS, line 1012 of unibitmapgeneric.inc
$0000000000842170 DRAWGAUGENEEDLE, line 394 of dtanaloggauge.pp
$0000000000841334 DRAWGAUGE, line 176 of dtanaloggauge.pp
$00000000008422F0 PAINT, line 455 of dtanaloggauge.pp
$0000000000584560 WMPAINT, line 58 of include/graphiccontrol.inc
$0000000000435B64
$0000000000579930 WNDPROC, line 2299 of include/control.inc
$0000000000577A24 PERFORM, line 1625 of include/control.inc
$0000000000569984 PAINTCONTROLS, line 4970 of include/wincontrol.inc
$00000000005696A4 PAINTHANDLER, line 4881 of include/wincontrol.inc
$000000000056E300 WMPAINT, line 6825 of include/wincontrol.inc
$0000000000584C7C WMPAINT, line 103 of include/customcontrol.inc
$0000000000435B64
$0000000000579930 WNDPROC, line 2299 of include/control.inc
Call trace for block $0000007FA4533AA0 size 0
$00000000009504A4 GETCUSTOMPENSTYLE, line 1159 of bgrapen.pas
$00000000009511D8 COMPUTEPOLYLINE, line 1288 of bgrapen.pas
$00000000008649A8 DRAWLINEANTIALIAS, line 1012 of unibitmapgeneric.inc
$0000000000841D44 DRAWGAUGESCALE, line 352 of dtanaloggauge.pp
$0000000000841324 DRAWGAUGE, line 175 of dtanaloggauge.pp
$00000000008422F0 PAINT, line 455 of dtanaloggauge.pp
$0000000000584560 WMPAINT, line 58 of include/graphiccontrol.inc
$0000000000435B64
$0000000000579930 WNDPROC, line 2299 of include/control.inc
$0000000000577A24 PERFORM, line 1625 of include/control.inc
$0000000000569984 PAINTCONTROLS, line 4970 of include/wincontrol.inc
$00000000005696A4 PAINTHANDLER, line 4881 of include/wincontrol.inc
$000000000056E300 WMPAINT, line 6825 of include/wincontrol.inc
$0000000000584C7C WMPAINT, line 103 of include/customcontrol.inc
$0000000000435B64
$0000000000579930 WNDPROC, line 2299 of include/control.inc
Task manager startup +-26MB
Tasm manager +-10 hours 127.4MB VM at 143MB
Hope it can be resolved. Great componenet.
The text was updated successfully, but these errors were encountered: