In Delphi I have configured to report memory leaks:
{$IFDEF Debug}
ReportMemoryLeaksOnShutdown := true;
{$ENDIF}
After exiting the program I get the following message:
My program is very big and I have no clue how to find the TStringList which I have created but not freed.
Unfortunately Delphi has no garbage collector...
If I search in my project for TStringList
I find ~500 occurences. It doesn't make any sense to check all of them.
How can I find the variable which I forgot to free?
The following software helps to hunt memory leaks:
https://github.com/shadow-cs/delphi-leakcheck
Here the steps to follow:
cd C:\Delphi
git clone https://github.com/shadow-cs/delphi-leakcheck
C:\Delphi\delphi-leakcheck\Source
to your Delphi library path (Tools/Options/...)MyProject.dpr
file:Code:
uses
// LeakCheck, // Does not need do be defined here (LeakCheck.Report will do it) unless you want to reference it from the DPR
LeakCheck.Report, // Me first! - I don't have any dependencies but LeakCheck so I finalize after all other units
LeakCheck.Setup.Trace, // (Optional) Then me - Run setup to configure stack tracing for us
LeakCheck.Report.FileLog, // Then me - I'm the one that pulls some dependencies and have all the functionality
C:\Delphi\MyProject\MyProject.log
was created.This approach solved my problem within several minutes.
Bonus: this software is completely free - you don't have to pay anything for it