To enable leak detection, just add this inside the main program file (.dpr
):
ReportMemoryLeaksOnShutdown := true;
In effect, the memory leaks (if any) will be reported when the application ends. The leaks are reported as a GUI dialog when the application is a GUI ({$apptype GUI}
, default with Delphi compiler). When the application is using a console ({$apptype CONSOLE}
), the leaks are reported on the console. There’s nothing reported when there are no leaks.
If you’d like to show leaks only when running inside the debugger in Delphi IDE, you can make it conditional on DebugHook, like this:
ReportMemoryLeaksOnShutdown := DebugHook <> 0;
Note
|
It is only reports leaks on the Windows platform. But it compiles everywhere, there’s no need to use {$ifdef MSWINDOWS} around it.
|