Recent

Author Topic: Exiting HeapTrace dump  (Read 575 times)

jamie

  • Hero Member
  • *****
  • Posts: 7663
Exiting HeapTrace dump
« on: March 16, 2026, 12:30:32 am »
At times I run the APP outside of the debugger and still have HeapTrc enabled in the code, so if for some reason there is a dump at app exit and at times it can be large, is there a way that I don't know about to abort with a key stroke of something?

  I tried using the X, that don't work it only just gives you the next page and on and on.

Jamie
The only true wisdom is knowing you know nothing

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: Exiting HeapTrace dump
« Reply #1 on: March 16, 2026, 08:22:33 am »
hmmmm.... have you tried this? https://wiki.lazarus.freepascal.org/heaptrc#Programmatically_disable_report
Quote
Programmatically disable report

If the UseHeapTrace variable is false when the program exits, then the leak will not be reported, even if it is detected. You can use this in your code:

But i have no idea when that report-dialogue fires
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 18982
  • Glad to be alive.
Re: Exiting HeapTrace dump
« Reply #2 on: March 16, 2026, 10:11:53 am »
At times I run the APP outside of the debugger and still have HeapTrc enabled in the code, so if for some reason there is a dump at app exit and at times it can be large, is there a way that I don't know about to abort with a key stroke of something?

  I tried using the X, that don't work it only just gives you the next page and on and on.

Jamie
- Heaptrc is NOT running under the debugger persé, although it is a debugger tool. It does not need the debugger.
- You need to manually disable it as per my wiki entry instructions.
- What you want is possible if there is a good enough IsDebuggerPresent function like in Delphi.

For Windows this is easy, but not cross-platform:

Code: Pascal  [Select][+][-]
  1. program testdebug;
  2. {$apptype console}{$mode objfpc}
  3. function IsDebuggerPresent () : Boolean stdcall; external 'kernel32.dll';
  4.  
  5. begin
  6.   {$if declared(UseHeapTrace)}
  7.   writeln('compiled with the heaptrc unit');
  8.   if IsDebuggerPresent then UseHeaptrace := true else UseHeaptrace := false;
  9.   writeln('Heaptrace is used ?  ',UseHeaptrace);
  10.   {$else}
  11.   writeln('not compiled with the heaptrc unit');
  12.   {$endif}
  13.   readln;
  14. end.      

« Last Edit: March 16, 2026, 10:32:29 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: Exiting HeapTrace dump
« Reply #3 on: March 16, 2026, 10:31:42 am »
hmmm.... https://forum.lazarus.freepascal.org/index.php/topic,34244.msg223818.html#msg223818

i like the option with commandline-parameter, and then checking for it in code.
And then use the variable from my answer above
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 18982
  • Glad to be alive.
Re: Exiting HeapTrace dump
« Reply #4 on: March 16, 2026, 10:34:52 am »
Posts crossed, I did an edit, but for the Windows situation I think my code is better and more in line with the current status of compiler and rtl.
1. test for presence of heaptrc
2. test for debugger present
3. test if heaptrc is actually active
4. set heaptrc active only when running under the debugger, else turn its functionality off.

If it runs stand-alone there is never heaptrace output.
« Last Edit: March 16, 2026, 10:40:25 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: Exiting HeapTrace dump
« Reply #5 on: March 16, 2026, 10:56:15 am »
Posts crossed, I did an edit, but for the Windows situation I think my code is better and more in line with the current status of compiler and rtl.
1. test for presence of heaptrc
2. test for debugger present
3. test if heaptrc is actually active
4. set heaptrc active only when running under the debugger, else turn its functionality off.

If it runs stand-alone there is never heaptrace output.
Hmmm.....True.
But i understood TS' "...outside the debugger" as "Outside the IDE", because let's be honest: Debugger-use is in 99.99999% of cases from IDE.
Nevermind, that you can start without Debugger from IDE
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

runewalsh

  • Full Member
  • ***
  • Posts: 115
Re: Exiting HeapTrace dump
« Reply #6 on: March 16, 2026, 11:19:15 am »
Are you on Windows? In trunk, there is a “Cancel” button that skips the remaining messageboxes (and a default limit of 1024 reported leaks, which can still lead to 1024+ messageboxes, though).
Or fix the leaks already XD.
Or use {$apptype console}.
Or call SetHeapTraceOutput('heap.log'), and then periodically remove heap.log because new logs are appended to it, not overwrite it.
(SetHeapTraceOutput('nul') is possible but not much better than just disabling heaptrc.)

jamie

  • Hero Member
  • *****
  • Posts: 7663
Re: Exiting HeapTrace dump
« Reply #7 on: March 16, 2026, 11:34:49 am »
The cancel button is exactly what i want, the reason why it hasn't been implemented long before this it alludes me.

Jamie
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018