在 Delphi 中,我通常会像这样编写一个简单的泄漏测试:
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.
如何在 Free Pascal/Lazarus 中检测内存泄漏?