Recent

Author Topic: Heap dump by heaptrc unit on Windows  (Read 11023 times)

ricardo.consolo

  • New Member
  • *
  • Posts: 17
Heap dump by heaptrc unit on Windows
« on: March 01, 2017, 01:51:11 pm »
Hi.

When in debug mode (Windows 7 32 bits), I got this message when closing the application:

---------------------------
Error
---------------------------
Heap dump by heaptrc unit
9426 memory blocks allocated : 2495279/2522280
9426 memory blocks freed     : 2495279/2522280
0 unfreed memory blocks : 0
True heap size : 294912
True free heap : 294832
Should be : 294912

---------------------------
OK   
---------------------------

The same application does not show that on Linux (Centos 6 32 bits).

Any clue?

Thanks.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Heap dump by heaptrc unit on Windows
« Reply #1 on: March 01, 2017, 02:15:10 pm »
Perhaps on Linux the heaptrc output is being sent to a nonexistent or hidden window, or maybe your Linux compilation setup is not set to generate heaptrc output at all.

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Heap dump by heaptrc unit on Windows
« Reply #2 on: March 01, 2017, 02:57:30 pm »
Linux sends it to the standard output.

avra

  • Hero Member
  • *****
  • Posts: 2593
    • Additional info
Re: Heap dump by heaptrc unit on Windows
« Reply #3 on: March 01, 2017, 03:33:23 pm »
Have you tried to uncheck "Use Heaptrc unit" in Project options / compiler options / debugging ?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 19387
  • Glad to be alive.
Re: Heap dump by heaptrc unit on Windows
« Reply #4 on: March 01, 2017, 04:52:57 pm »
And fortunately heaptrc also reports there's not much wrong with your code?  O:-) That memory will be free'd.
If you want to use the heaptrc unit and keep it (only with -gh,not as an include in the uses clause)  there's also the option to compile with UseHeapTrace:= False.
Which skips the report.

But make sure that you did not add heaptrc to a uses clause anywhere yourself!. See the recent wiki.
http://wiki.freepascal.org/heaptrc

Avra's pointer is correct by the way: that selects or un-selects -gh for you.
« Last Edit: March 01, 2017, 05:00:45 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

ricardo.consolo

  • New Member
  • *
  • Posts: 17
Re: Heap dump by heaptrc unit on Windows
« Reply #5 on: March 01, 2017, 10:05:55 pm »
Thanks for the info.

I have checked them all and got it working.

FYK, Linux output happens only when running the app from the terminal.

Also, there was a bad destroy method in my code that I fixed.

Thanks.

michaelthuma

  • Jr. Member
  • **
  • Posts: 51
Re: Heap dump by heaptrc unit on Windows
« Reply #6 on: November 17, 2017, 03:52:17 pm »
View-Debug Windows - Console Output


Thanks for the info.

I have checked them all and got it working.

FYK, Linux output happens only when running the app from the terminal.

Also, there was a bad destroy method in my code that I fixed.

Thanks.

HenrikErlandsson

  • New Member
  • *
  • Posts: 39
  • ^ Happy coder :)
    • Coppershade
Re: Heap dump by heaptrc unit on Windows
« Reply #7 on: July 02, 2026, 12:24:27 am »
This persists. I have no memory leaks, but always get this dialog to close with 112 bytes diff (which will be freed).

Obviously I don't want to uncheck Use heaptrc unit in Debug mode, because then I won't catch actual leaks.

It appeared when I used the "Create Debug and Release modes". Before that, I had been debugging a lot, without it appearing on every program exit.

I was using Dwarf 3 beta before creating debug and release modes, and after. It seems this is related to IDE/settings somehow.
6502 / Z80 / Amiga / ARM assembler, Pascal, Delphi, Lingo, Obj-C, Lua, FPC, C# + web front-/backend.

n7800

  • Hero Member
  • *****
  • Posts: 729
  • Lazarus IDE contributor
    • GitLab profile
Re: Heap dump by heaptrc unit on Windows
« Reply #8 on: July 02, 2026, 12:57:02 am »
It appeared when I used the "Create Debug and Release modes". Before that, I had been debugging a lot, without it appearing on every program exit.

I was using Dwarf 3 beta before creating debug and release modes, and after. It seems this is related to IDE/settings somehow.

By default, a new project is created in the "Default" build mode, which disables this checkbox. In "Debug" mode, it is enabled. You can leave debug mode (with all its other options) enabled, but disable this checkbox. Personally, I only enable it occasionally.

This persists. I have no memory leaks, but always get this dialog to close with 112 bytes diff (which will be freed).

If you create a new empty project and enable this checkbox (or create a "Debug" mode), will the 112-byte leak message persist?

The leak could be in the units you're using (even the standard ones). By the way, what version of Lazarus and FPC are you using?

n7800

  • Hero Member
  • *****
  • Posts: 729
  • Lazarus IDE contributor
    • GitLab profile
Re: Heap dump by heaptrc unit on Windows
« Reply #9 on: July 02, 2026, 01:06:25 am »
This persists. I have no memory leaks, but always get this dialog to close with 112 bytes diff (which will be freed).

By the way, the report should indicate exactly where the leak is (that's the whole point). Does it indicate anything useful or just memory addresses?

mas steindorff

  • Hero Member
  • *****
  • Posts: 601
Re: Heap dump by heaptrc unit on Windows
« Reply #10 on: July 02, 2026, 03:59:32 am »
in your project file add
Code: Pascal  [Select][+][-]
  1.  {$if declared(UseHeapTrace)}
  2.   GlobalSkipIfNoLeaks := true;
  3.  {$endif}  
  4.  
after  Application.Run; and before end.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Bart

  • Hero Member
  • *****
  • Posts: 5743
    • Bart en Mariska's Webstek
Re: Heap dump by heaptrc unit on Windows
« Reply #11 on: July 02, 2026, 10:30:51 am »
This persists. I have no memory leaks, but always get this dialog to close with 112 bytes diff (which will be freed).

Obviously I don't want to uncheck Use heaptrc unit in Debug mode, because then I won't catch actual leaks.

It appeared when I used the "Create Debug and Release modes".

In my Debug build mode I have unchecked the option "Windows GUI application (-WG)" in Compiler Options -> Config and Target.
This also allow mee to see debugln() output on the console.

Bart

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12513
  • Debugger - SynEdit - and more
    • wiki
Re: Heap dump by heaptrc unit on Windows
« Reply #12 on: July 02, 2026, 10:45:04 am »
There are a number of possible questions/answers.

First it says 0 bytes leaked so that is ok.

If the question is the True heap difference => I vaguely recall having read that this is memory that gets allocated by the system unit before heaptrc is fully initialized. Therefore it does not get properly accounted...
If that is so, then the presence and/or size of that gap may vary for different targets, as the system unit includes target specific code...


If the question is: why do I get a popup on windows, but not on Linux... Linux always has StdOut (even if it goes to /dev/nil)
Heaptrc itself prints to stdout (or stderr, but I think stdout). That fails (runtime error on closed handle) on Windows for GUI apps. So the LCL (or LazUtils, something...) redirects this into a popup.
Heaptrc iirc always prints a message. Either that there is a leak, or that there is not. So on Windows you do get that popup (unless you redirect heaptrc to a file, or silence it otherwise). On Linux it just prints to stdout, never mind where that goes.

 

TinyPortal © 2005-2018