This project (with heaptrc) gives mem leaks on exit lazarus / 31-LCL ---------------------------------------------------------------------- AlexTP · 2022-05-02 17:52 On both Qt5 and Gtk2 the project (attached) gives lot of mem leaks, on exit. Run it on Linux Terminal. Project has 'use heaptrc' flag cheched. What am I doing wrong? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i { TForm1 } const  crNiceScrollNone  = TCursor(-30);  crNiceScrollUp    = TCursor(-31);  crNiceScrollDown  = TCursor(-32);  crNiceScrollLeft  = TCursor(-33);  crNiceScrollRight = TCursor(-34); procedure TForm1.FormCreate(Sender: TObject);begin  FBmp := TPortableNetworkGraphic.Create;  FBmp.LoadFromResourceName(HInstance, 'AB_MOVE');   Cur0:= LoadCursor(HInstance, 'AB_MOVE');  Cur1:= LoadCursor(HInstance, 'AB_MOVE_U');  Cur2:= LoadCursor(HInstance, 'AB_MOVE_D');  Cur3:= LoadCursor(HInstance, 'AB_MOVE_L');  Cur4:= LoadCursor(HInstance, 'AB_MOVE_R');   Screen.Cursors[crNiceScrollNone]  := Cur0;  Screen.Cursors[crNiceScrollUp]    := Cur1;  Screen.Cursors[crNiceScrollDown]  := Cur2;  Screen.Cursors[crNiceScrollLeft]  := Cur3;  Screen.Cursors[crNiceScrollRight] := Cur4;end; procedure TForm1.FormDestroy(Sender: TObject);begin  DestroyCursor(Cur4);  DestroyCursor(Cur3);  DestroyCursor(Cur2);  DestroyCursor(Cur1);  DestroyCursor(Cur0);   FreeAndNil(FBmp);end;  I tried to remove 'DestroyCursor' lines (LCL does it auto), still the same leaks. ---------------------------------------------------------------------- winni · 2022-05-02 19:03 Hi! All predefined cursor constants are negativ. So you can use the positiv values for your own use. Omit the intermediate variables. I did it that way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constcrRealHourGlass   =  1;....Screen.Cursors[crRealHourGlass]:=LoadC ursorFromLazarusResource('hourglass');  Winni ---------------------------------------------------------------------- AlexTP · 2022-05-02 20:23 So if I will use positive constants, I won't see mem leaks on exit? No, I tried it now - mem leaks still here! ---------------------------------------------------------------------- howardpc · 2022-05-02 21:08 The following compiles and runs without leaks. Whether it does what you want, I don't know. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, LCLIntf; type   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);  private    FBmp: TPortableNetworkGraphic;  end; var  Form1: TForm1; implementation {$R res/atbinhexresources.res}{$R *.lfm} const  crNiceScrollNone  = TCursor(-30);  crNiceScrollUp    = TCursor(-31);  crNiceScrollDown  = TCursor(-32);  crNiceScrollLeft  = TCursor(-33);  crNiceScrollRight = TCursor(-34); procedure TForm1.FormCreate(Sender: TObject);begin  FBmp := TPortableNetworkGraphic.Create;  FBmp.LoadFromResourceName(HInstance, 'AB_MOVE');   Screen.Cursors[crNiceScrollNone]  := LoadCursor(HInstance, 'AB_MOVE');  Screen.Cursors[crNiceScrollUp]    := LoadCursor(HINSTANCE, 'AB_MOVE_U');  Screen.Cursors[crNiceScrollDown]  := LoadCursor(HINSTANCE, 'AB_MOVE_D');  Screen.Cursors[crNiceScrollLeft]  := LoadCursor(HINSTANCE, 'AB_MOVE_L');  Screen.Cursors[crNiceScrollRight] := LoadCursor(HINSTANCE, 'AB_MOVE_R');end; procedure TForm1.FormDestroy(Sender: TObject);begin  FreeAndNil(FBmp);end; end. ---------------------------------------------------------------------- Josh · 2022-05-02 21:20 hi I thought the form would destroy cur1 etc on its own when exited, as they are part of the form container. or am i wrong.? ---------------------------------------------------------------------- AlexTP · 2022-05-03 06:40 @howardpc, QuoteThe following compiles and runs without leaks. I cannot confirm that - still the same leaks, on Gtk2/Qt5. Make sure you checked the IDE option 'use heaptrc'. ---------------------------------------------------------------------- paweld · 2022-05-03 07:12 @AlexTP Quote@howardpc, QuoteThe following compiles and runs without leaks. I cannot confirm that - still the same leaks, on Gtk2/Qt5. Make sure you checked the IDE option 'use heaptrc'. on Gtk2 no leaks, tetsed on Manjaro Xfce, Lazarus trunk, fpc 3.2.2 ---------------------------------------------------------------------- PascalDragon · 2022-05-03 07:16 Quote from: josh on May 02, 2022, 11:20:01 pmI thought the form would destroy cur1 etc on its own when exited, as they are part of the form container. or am i wrong.? You are wrong, because you can't pass an owner to LoadCursor. This means it needs to be freed manually. ---------------------------------------------------------------------- AlexTP · 2022-05-03 07:17 @PascalDragon, can you confirm these mem leaks on gtk2/qt5?