Recent

Author Topic: Heaptrc and 'Win32 gui application'  (Read 4181 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Heaptrc and 'Win32 gui application'
« on: August 10, 2023, 10:09:16 am »
Lazarus 2.2.6, Windows 11.

If I uncheck 'Win32 gui application (-WG)' option and check 'Use Heaptrc unit (check for mem-leaks) (-gh)' option, then, after application ends, result of heaptrc is not shown in window, but is printed in console window.
Problem is that this console window closes immediately after application ends and I don't have time to inspect heaptrc results.

Is there an option to keep console window open after application ends?

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Heaptrc and 'Win32 gui application'
« Reply #1 on: August 10, 2023, 12:20:31 pm »
The use case as described is imho counterproductive (not starting from a console but do write to it) . If you need the output for (future) reference then you can use one of the environment options or use SetHeapTraceOutput.
Today is tomorrow's yesterday.

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Heaptrc and 'Win32 gui application'
« Reply #2 on: August 11, 2023, 08:54:54 am »
Is there an option to force result of heaptrc to show in window then?

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Heaptrc and 'Win32 gui application'
« Reply #3 on: August 11, 2023, 09:00:22 am »
Lazarus, menu/view/leaks and traces was meant for that purpose but, I have a hunch that is not what you meant when you asked that question ?
Today is tomorrow's yesterday.

Thaddy

  • Hero Member
  • *****
  • Posts: 19272
  • Glad to be alive.
Re: Heaptrc and 'Win32 gui application'
« Reply #4 on: August 11, 2023, 09:00:55 am »
Reading documentation seems to be an art... This is an annoying question to me...
You've got everything on a plate and still open a new topic?
objects are fine constructs. You can even initialize them with constructors.

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Heaptrc and 'Win32 gui application'
« Reply #5 on: August 11, 2023, 09:16:48 am »
Reading documentation seems to be an art... This is an annoying question to me...
You've got everything on a plate and still open a new topic?

You mean this: https://www.freepascal.org/docs-html/rtl/heaptrc/usage.html?

I am not native English speaker, but I don't see how this documentation answers my question.

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Heaptrc and 'Win32 gui application'
« Reply #6 on: August 11, 2023, 09:48:05 am »
Lazarus, menu/view/leaks and traces was meant for that purpose but, I have a hunch that is not what you meant when you asked that question ?

Exactly.
Leaks and Traces are fine when chasing some memory leak, but when I develop something I like to have heaptrc on so I just have glance after every test run.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Heaptrc and 'Win32 gui application'
« Reply #7 on: August 13, 2023, 07:01:04 am »
@dseligo:
Not sure if this works for Windows (it does on Linux) but when you run your application using the debugger there is an option to view the console output, View/Debug Windows/Console Input/output (default keybinding ctrl-alt-O).

If that doesn't work for you then you could consider writing a small GUI application that checks for the existence of a trace-file and display the contents (silent exit when no (current) heaptrace present) which can be run when you configure: Project/Project Options/Compiler Options/Compiler Commands then at Execute After, Call on (only) run and the command to run being your heaptrace viewer.

I am not aware of another way to accomplish something what is similar as you seem to be looking for.
Today is tomorrow's yesterday.

440bx

  • Hero Member
  • *****
  • Posts: 6540
Re: Heaptrc and 'Win32 gui application'
« Reply #8 on: August 13, 2023, 09:28:23 am »
Is there an option to keep console window open after application ends?
One way would be to check if $apptype is _not_ gui then execute a conditional readln before the app ends.  That will cause the terminal window to remain open until a carriage return.

Note that since $IFOPT doesn't work with $APPTYPE, you'll need to define a symbol to control the APPTYPE and the execution of the readln.

HTH.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Heaptrc and 'Win32 gui application'
« Reply #9 on: August 13, 2023, 10:41:42 am »
One way would be to check if $apptype is _not_ gui then execute a conditional readln before the app ends.  That will cause the terminal window to remain open until a carriage return.
The problem is that the heaptrc notice comes after the end of program so it's also after the readln. So this won't work.

440bx

  • Hero Member
  • *****
  • Posts: 6540
Re: Heaptrc and 'Win32 gui application'
« Reply #10 on: August 13, 2023, 11:50:48 am »
The problem is that the heaptrc notice comes after the end of program so it's also after the readln. So this won't work.
I didn't know that.  Thank you for pointing it out. 

If you don't mind, I have a question, how does heaptrc make itself a step in the closing of the program ?... I'm asking because maybe the same mechanism can be used to insert a readln just before the call to EndProcess is made.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Heaptrc and 'Win32 gui application'
« Reply #11 on: August 13, 2023, 12:15:07 pm »
... how does heaptrc make itself a step in the closing of the program ?... I'm asking because maybe the same mechanism can be used to insert a readln just before the call to EndProcess is made.
TRon already mentioned recalling the console-debug-window with Ctrl+Alt+O
Mentioned here: https://wiki.freepascal.org/heaptrc

heaptrc attaches itself as first unit so it will always be the last to execute.
Even assigning your own ExitProc won't work.

Maybe you could call SetHeapExtraInfo with your own displayproc and set a readln in there.
https://www.freepascal.org/docs-html/rtl/heaptrc/setheapextrainfo.html

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: Heaptrc and 'Win32 gui application'
« Reply #12 on: August 13, 2023, 04:24:30 pm »
How about setting the heaptrc output to a file instead, and use leakview to see the report
https://wiki.lazarus.freepascal.org/heaptrc

 

TinyPortal © 2005-2018