Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate ReportMemoryLeaksOnShutdown only in debug mode?

Tags:

delphi

I need to activate the ReportMemoryLeaksOnShutdown functionality to report the memory leaks of my application, but only under debug mode (when the Delphi IDE is running). How can I do this?

like image 556
Salvador Avatar asked Mar 15 '11 20:03

Salvador


3 Answers

I usually use the IsDebuggerPresent API function and also surround it with a DEBUG symbol check so the code doesn't end up in release builds:

{$IFDEF DEBUG}   
  ReportMemoryLeaksOnShutDown := IsDebuggerPresent();
{$ENDIF}

The function should already be declared in the Windows unit, if you're not using an ancient version of Delphi and works on Windows 2000 and newer.

like image 188
Goran Skledar Avatar answered Oct 22 '22 04:10

Goran Skledar


If you mean "debug mode" as compiled using the Debug build configuration (D2007+), you'll have the DEBUG symbol defined, so you can activate the ReportMemoryLeaksOnShutdown even when running oustide the debugger with:

{$IFDEF DEBUG}
  ReportMemoryLeaksOnShutdown := True;
{$ENDIF}

If you want to run only if the debugger is present, look at RRUZ answer

like image 27
jachguate Avatar answered Oct 22 '22 02:10

jachguate


try using the DebugHook variable

ReportMemoryLeaksOnShutdown:=DebugHook<>0;
like image 23
RRUZ Avatar answered Oct 22 '22 02:10

RRUZ