In Delphi, I usually write a simple leak test like this:
program MemLeak;
{$APPTYPE CONSOLE}
uses
SysUtils;
procedure Leak;
begin
{ Put leaking code here. }
end;
begin
ReportMemoryLeaksOnShutdown:= True;
try
Leak;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
How do I detect memory leaks in Free Pascal/Lazarus?
Free Pascal has a similar feature. At the end of the program, call
DumpHeap, or enable the heaptrc option in the Lazarus project settings. The output file can be set with theSetHeapTraceOutputmethod. Both methods are in the unitheaptrcwhich must be the first in the project (to capture allocations from start).More information:
Leak visualization: the Lazarus package “LeakView” presents the content of a heap trace output file in a tree view. It is included in the default installation and available after a rebuild of the IDE. (not yet tested by me)
The output looks like:
(tested with Free Pascal 2.6.0)