Recent

Author Topic: Problem removing Heaptrc information for application running on Windows  (Read 482 times)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 607
* Mac Mini M1
* macOS 14.6.1
* Windows 11 Pro (runnings as a VM in VMWare Fusion)
* Lazarus 3.99
* FPC 3.3.1

I was using Heaptrc to track some memory leaks a few days ago. I bypassed the Debug code in my project file...
Code: Pascal  [Select][+][-]
  1. program osmosepresets;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. {.$DEFINE debug}  // "." suppreses debug definition
  6.  
  7. uses
  8.   {$IFDEF UNIX}
  9.   cthreads,
  10.   {$ENDIF}
  11.   {$IFDEF HASAMIGA}
  12.   athreads,
  13.   {$ENDIF}
  14.   caMidi,
  15.   caMidiIntf,
  16.   caMidiTypes,
  17.   Interfaces, // this includes the LCL widgetset
  18.   SysUtils,
  19.   Forms,
  20.   uMainForm,
  21.   uData,
  22.   uSettingsForm,
  23.   uSettingsData;
  24.  
  25.   //{$R *.res}
  26.  
  27.   {$IFDEF DEBUG}
  28. const HeaptrcPath = '/Users/carlcaulkett/Code/FPC/OsmosePresets/heaptrc.txt';
  29.   {$ENDIF DEBUG}
  30.  
  31. begin
  32.   {$IFDEF DEBUG}
  33.   // Assuming your build mode sets -dDEBUG in Project Options/Other when defining -gh
  34.   // This avoids interference when running a production/default build without -gh
  35.  
  36.   // Set up -gh output for the Leakview package:
  37.   if FileExists(HeaptrcPath) then
  38.     DeleteFile(HeaptrcPath);
  39.   SetHeapTraceOutput(HeaptrcPath);
  40.   {$ENDIF DEBUG}
  41.   RequireDerivedFormResource := True;
  42.   Application.Scaled := True;
  43.   Application.Initialize;
  44.   Application.CreateForm(TMainForm, MainForm);
  45.   Application.Run;
  46. end.  
  47.  

I also unchecked the option in "Project Options" -> "Compiler Options" -> "Debugging" -> "Use Heaptrc unit (check for mem-leaks) (-gh)"

Yet when I run the app as a cross-compiled Windows app, when I terminate it, I get 5 pages of what look like memory address. Noticeably, on the second page, Heaptrc is mentioned, despite my attempts to stop it being used...

How can I suppress this display of memory addresses?

And please don't tell me that, it's for my own good, and that I should get rid of the memory leaks. That process is in hand by other means!
« Last Edit: October 13, 2024, 01:03:05 am by carl_caulkett »
"It builds... ship it!"

jamie

  • Hero Member
  • *****
  • Posts: 6683
Re: Problem removing Heaptrc information for application running on Windows
« Reply #1 on: October 13, 2024, 01:13:04 am »
Will, maybe that is a good thing? I think it's trying to tell you something! :D

Try Rebuilding the app after you have removed the option!
The only true wisdom is knowing you know nothing

carl_caulkett

  • Hero Member
  • *****
  • Posts: 607
Re: Problem removing Heaptrc information for application running on Windows
« Reply #2 on: October 13, 2024, 01:25:34 am »
I added the "Heaptrc" option to the "Debugging" section of "Project Options", enabling me to add the line...
Code: Pascal  [Select][+][-]
  1.   UseHeapTrace := false;
  2.  

to my ".lpr" file. This has reduced the count of screens on termination from 5 down to 2, but this is still 2 too many!

@jamie You may be surprise to learn that it had actually occurred to me that the app might need rebuilding after such a change :o
"It builds... ship it!"

jamie

  • Hero Member
  • *****
  • Posts: 6683
Re: Problem removing Heaptrc information for application running on Windows
« Reply #3 on: October 13, 2024, 01:30:24 am »
Why did you add that line?

Do not add on your own the units or references to them because they will still be there, let the project settings handle that.

all you need to do is simply checkmark it in the project debug settings, that's it. no additional units or settings you should do.

The project manager will manage that instead.
The only true wisdom is knowing you know nothing

carl_caulkett

  • Hero Member
  • *****
  • Posts: 607
Re: Problem removing Heaptrc information for application running on Windows
« Reply #4 on: October 13, 2024, 01:30:53 am »
A search has revealed this thread https://forum.lazarus.freepascal.org/index.php/topic,39109.msg267265.html#msg267265 which suggests that I might be attempting to free already freed objects, which is entirely possible!

It can wait till the morning  ;)
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 607
Re: Problem removing Heaptrc information for application running on Windows
« Reply #5 on: October 13, 2024, 01:38:32 am »
Why did you add that line?

Do not add on your own the units or references to them because they will still be there, let the project settings handle that.

all you need to do is simply checkmark it in the project debug settings, that's it. no additional units or settings you should do.

The project manager will manage that instead.

I understand all that! I did not add any use clause reference to Heaptrc. Reinstating the check box in Project options was enough to enable me to use the "UseHeapTrace := false;", which evidently worked.

It highlighted the fact that I have a certain amount of memory leaks, which I can track down, as I say, by other means, but that I have a separate issue of trying to free already freed objects.

"It builds... ship it!"

jamie

  • Hero Member
  • *****
  • Posts: 6683
Re: Problem removing Heaptrc information for application running on Windows
« Reply #6 on: October 13, 2024, 01:49:19 am »
When you get over the hump and maybe for that, use FreeAndNil instead. At least if you are attempting to double free something it will be ignored and you won't have crashes, however, I think in your case its not freeing objects.

 showing your code or parts of it may help. The heapTrc normally gives you a clue where to look.

P.S.
 I see no line numbers in those reports, strange, must be outside of known line numbers ?
« Last Edit: October 13, 2024, 01:52:56 am by jamie »
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 15935
  • Censorship about opinions does not belong here.
Re: Problem removing Heaptrc information for application running on Windows
« Reply #7 on: October 13, 2024, 07:18:00 am »
Not strange if line info is not selected. -glh See the wiki on how to properly use heaptrc.
« Last Edit: October 13, 2024, 12:29:16 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018