Forum > Debugger

Problems using `heaptrc`

(1/3) > >>

carl_caulkett:
* Mac Mini M1
* macOS 14.6.1
* Lazarus 3.4
* FPC 3.2.2

I am trying to use `heaptrc' to check my app for memory leaks. I've set the appropriate option in `Project Options' -> `Debugging` -> `Use Heaptrc unit (check for mem-leaks (-gl))` and following the advice on the wiki, I haven't added `heaptrc` to my uses clause.

I first tried adding the following code to my main form unit...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$DEFINE debug}    ...  {$IFDEF DEBUG}  // Assuming your build mode sets -dDEBUG in Project Options/Other when defining -gh  // This avoids interference when running a production/default build without -gh   // Set up -gh output for the Leakview package:  if FileExists('heap.trc') then    DeleteFile('heap.trc');  SetHeapTraceOutput('heap.trc');  {$ENDIF DEBUG} 
But the compiler couldn't find `SetHeapTraceOutput`. I moved this code to my `project.lpr` file and was able to build the project. However, on running the project, I could find no signs of `heap.trc` (I did a thorough disk search). Does this mean there were no leaks in my program (unlikely) or have I done something daft to hinder the reporting of leaks?

UPDATE: I even went as far as introducing a deliberate leak...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMain.FormCreate(Sender: TObject);begin  FPresetData := TPresetData.Create;  FLeak := TStringList.Create;end; procedure TMain.FormDestroy(Sender: TObject);begin  FPresetData.Free;end; 
No `heap.trc` was created here. What am I missing?

Thaddy:

--- Quote from: carl_caulkett on September 30, 2024, 01:18:28 pm --- and following the advice on the wiki, I haven't added `heaptrc` to my uses clause.

--- End quote ---
That is against the advice of the wiki, or did that change somehow?
The heaptrce unit should NEVER, EVER be added to the uses clause manually.
( Some vandal editted it, I just checked, will be removed)
The only ways to use heaptrce correctly is compiling with the option -gh -gl or select the dialog items in Lazarus.
NEVER add heaptrace manually. Florian himself explained why you should not do that.

If you see heaptrc in a uses clause, you know it is wrong code.

(What happens is this: the memory manager needs to be in place at the right time, including program start-up, when you add heaptrc to the uses clause instead of best practice, you will end up with TWO memory managers and the start-up code can not be resolved,)

Sheer vandalism, the wiki WAS correct. Who did that?   >:D >:D >:D >:D

carl_caulkett:
Read what I said... "and following the advice on the wiki, I haven't added `heaptrc` to my uses clause."
Note the use of the word "haven't", a contraction of the words "have not" 😉

Thaddy:
No it is not. The wiki was editted in a bad way. I will revert it.

carl_caulkett:
Sigh!

When I looked at the Wiki, it said NOT to add `heaptrc` to my uses clause, so I DID NOT add `heaptrc` to my uses clause!

This is what the wiki looked like when I read it earlier, and indeed what it looks like now.

And to what were you referring when you said "No it is not"? I hope you were not contradicting my explanation of the use of the word "haven't"  :o

Navigation

[0] Message Index

[#] Next page

Go to full version