如何仅在调试模式下激活ReportMemoryLeaksOnShutdown?

Sal*_*dor 11 delphi

我需要激活ReportMemoryLeaksOnShutdown功能来报告我的应用程序的内存泄漏,但只能在调试模式下(当Delphi IDE运行时).我怎样才能做到这一点?

jac*_*ate 27

如果您指的是使用Debug构建配置(D2007 +)编译的"调试模式",那么您将定义DEBUG符号,因此即使在运行oustide调试器时,您也可以激活ReportMemoryLeaksOnShutdown:

{$IFDEF DEBUG}
  ReportMemoryLeaksOnShutdown := True;
{$ENDIF}
Run Code Online (Sandbox Code Playgroud)

如果只想在调试器存在时运行,请查看RRUZ答案

  • +1我这样做.检测调试器感觉很脏. (7认同)

RRU*_*RUZ 23

尝试使用DebugHook变量

ReportMemoryLeaksOnShutdown:=DebugHook<>0;
Run Code Online (Sandbox Code Playgroud)

  • 可能会禁用与“ DebugHook”,“ {$ WARN SYMBOL_PLATFORM OFF}”相关的愚蠢警告。 (2认同)