How to activate ReportMemoryLeaksOnShutdown only in debug mode?

前端 未结 3 1097
深忆病人
深忆病人 2021-01-04 11:54

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

3条回答
  •  萌比男神i
    2021-01-04 12:30

    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.

提交回复
热议问题