Heaptrc and 'Win32 gui application' lazarus / 12-Debugger ---------------------------------------------------------------------- dseligo · 2023-08-10 08:09 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 · 2023-08-10 10:20 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. ---------------------------------------------------------------------- dseligo · 2023-08-11 06:54 Is there an option to force result of heaptrc to show in window then? ---------------------------------------------------------------------- TRon · 2023-08-11 07:00 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 ? ---------------------------------------------------------------------- Thaddy · 2023-08-11 07:00 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? ---------------------------------------------------------------------- dseligo · 2023-08-11 07:16 Quote from: Thaddy on August 11, 2023, 09:00:55 amReading 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 · 2023-08-11 07:48 Quote from: TRon on August 11, 2023, 09:00:22 amLazarus, 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 · 2023-08-13 05:01 @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. ---------------------------------------------------------------------- 440bx · 2023-08-13 07:28 Quote from: dseligo on August 10, 2023, 10:09:16 amIs 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. ---------------------------------------------------------------------- rvk · 2023-08-13 08:41 Quote from: 440bx on August 13, 2023, 09:28:23 amOne 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 · 2023-08-13 09:50 Quote from: rvk on August 13, 2023, 10:41:42 amThe 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. ---------------------------------------------------------------------- rvk · 2023-08-13 10:15 Quote from: 440bx on August 13, 2023, 11:50:48 am... 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 · 2023-08-13 14:24 How about setting the heaptrc output to a file instead, and use leakview to see the report https://wiki.lazarus.freepascal.org/heaptrc