Recent

Author Topic: Heap dump by heaptrc - ambiguous results  (Read 7185 times)

Mick

  • Jr. Member
  • **
  • Posts: 51
Heap dump by heaptrc - ambiguous results
« on: September 24, 2017, 12:24:54 am »
I'm getting ambiguous results in the heaptrc report for the debug build of my app with heap tracing enabled.
The app is 32-bit, cross compiled from 64-bit Lazarus 1.6.2 (FPC 3.0.0), SVN rev. 53354.
Built and running on the same machine and system (Win 7 64bit Pro).

Num blocks freed is equal to num blocks allocated, 0 unfreed memory blocks reported.
But the true heap size is different than true free heap, always by 112 bytes.

Is it something I should be worried about and investigate, or is it some known issue with heap dump report?
« Last Edit: September 24, 2017, 01:01:02 am by Mick »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Heap dump by heaptrc - ambiguous results
« Reply #1 on: September 24, 2017, 01:05:24 am »
As long as it says 0unfreed memory blocks you are ok. As for the heap it is pretty standard and has nothing to do with your code I'm trying hard to remember what I read about the difference and where but my memory fails me today.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Heap dump by heaptrc - ambiguous results
« Reply #2 on: September 24, 2017, 01:22:11 am »
If the numbers bother you (taazz is indeed correct, these couple of bytes are always 'gone' and probably come from heaptrace itself) then you can shut off the report when there are no leaks, by setting GlobalSkipIfNoLeaks to true.

Mick

  • Jr. Member
  • **
  • Posts: 51
Re: Heap dump by heaptrc - ambiguous results
« Reply #3 on: September 24, 2017, 02:35:42 am »
@taazz and @molly, thanks for the responses.

As for setting the GlobalSkipIfNoLeaks - how to do it exactly?
Is it supposed to be done by assigning the value from code (eg in .lpr source)?
In this case I will need to include the heaptrc unit to the uses clause and assign the value, right?
I believe that it should be done conditionally (only for debug mode with -gh turned on), right?
Then how to detect that the -gh option was enabled during the build?

To be honest - I'd like to avoid that "manual" solution.
It is more convenient for me to use the project build mode options "automagic" (include unit by setting the build option flag -gh).
So, is there maybe some commandline parameter that sets the value of this GlobalSkipIfNoLeaks flag?

EDIT: OK, I've found that conditional:
Code: Pascal  [Select][+][-]
  1. {$if declared(UseHeapTrace)}
in the wiki article: http://wiki.freepascal.org/heaptrc
Also found that unfortunately for me (still on FPC 3.0.0) I cannot use the GlobalSkipIfNoLeaks flag, only FPC 3.0.2 and above support it.

For now I can live with that warning, after upgrading I'll try to use this approach.
« Last Edit: September 24, 2017, 02:53:44 am by Mick »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Heap dump by heaptrc - ambiguous results
« Reply #4 on: September 24, 2017, 07:26:24 pm »
When there is a normal difference between heap size and free heap, it is announced next to true heap size. As shown in the picture in the wiki:
 "True heap size: 655360 (144 used in System startup)."
 "True free heap: 655216"

When the difference is unexpected, it will be as shown in the picture in your first post.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Heap dump by heaptrc - ambiguous results
« Reply #5 on: September 24, 2017, 08:08:40 pm »
Also found that unfortunately for me (still on FPC 3.0.0) I cannot use the GlobalSkipIfNoLeaks flag, only FPC 3.0.2 and above support it.
Sorry about that, as it escaped me that this was present only in FPC > 3.0. I''ve used trunk (and now 3.0.2) for too long i guess  :-[

Mick

  • Jr. Member
  • **
  • Posts: 51
Re: Heap dump by heaptrc - ambiguous results
« Reply #6 on: September 25, 2017, 12:21:46 am »
When there is a normal difference between heap size and free heap, it is announced next to true heap size. As shown in the picture in the wiki:
 "True heap size: 655360 (144 used in System startup)."
 "True free heap: 655216"

When the difference is unexpected, it will be as shown in the picture in your first post.

So, should I understand that this difference of 112 (bytes? blocks?) that is always reported for my app is to be treated as unexpected?
And probably there is some leak?
I'm a bit confused now.%)

FYI it is a Win32 GUI app and nevermind what I do in the app, the results are always the same.
Even open and immediately close the main window, the difference of 112 (bytes? blocks? still not sure what is the unit here) is reported.
The report is exactly the same if I do some heavy usage of the app (and believe me, there is a whole lot of allocations being done then).
However, I also have some memory allocated/freed in FormCreate/FormDestroy event handlers, so that the difference can be caused by them.

But wait...
When writing this post I wanted to double-check the behaviour and I have discovered something...
The previous screenshot was taken after running the debug build executable directly from Windows Explorer.
But the report by heaptrc is a bit different in case when I launch the app from IDE by F9 ("Run") in debug build mode.
Now the difference is bigger (208), but it is explicitly stated that the difference comes from "(208 used in System startup)"
 %)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Heap dump by heaptrc - ambiguous results
« Reply #7 on: September 25, 2017, 01:02:38 am »
The important line is #4:
  0 unfreed memory blocks : 0

This indicates there is no memory leak (or strictly speaking, that heaptrc has not found a memory leak).
The caption "Error" in the window title bar is highly misleading in this case.

Mick

  • Jr. Member
  • **
  • Posts: 51
Re: Heap dump by heaptrc - ambiguous results
« Reply #8 on: September 25, 2017, 01:42:16 am »
Thanks @howardpc. In that case the caption is misleading, indeed.
So I will use that trick with setting the GlobalSkipIfNoLeaks after I will upgrade to the more recent FPC version.
Now it is not a best moment for me to do that, so for now - I can live with the dialog popping up even if there are no leaks.
Thank you all for the responses.

braunbär

  • Newbie
  • Posts: 4
Re: Heap dump by heaptrc - ambiguous results
« Reply #9 on: December 08, 2020, 05:52:52 pm »
Why does that dialog pop up at all, when everything is ok?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Heap dump by heaptrc - ambiguous results
« Reply #10 on: December 08, 2020, 05:57:18 pm »
Well, I don't know but its a good reminder to ensure you turn that feature off at some point before shipping! ;)

actually I thought there was an option to have it not popup if all was ok but in cases like this, you will see that all isn't 100% perfect although there really isn't much to worry about..
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Heap dump by heaptrc - ambiguous results
« Reply #11 on: December 08, 2020, 07:18:29 pm »
Why does that dialog pop up at all, when everything is ok?

Because it's a debugging aid: it's frequently as (or more) important to know that all went well than to know it failed, and it also gives you some statistics about memory usage.

But Jamie is right: HeapTrc shouldn't be there in a release, like the rest of debugging info, etc.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Heap dump by heaptrc - ambiguous results
« Reply #12 on: December 09, 2020, 03:56:30 pm »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018