Recent

Author Topic: heaptrc error, lazarus 1.6.4  (Read 3677 times)

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
heaptrc error, lazarus 1.6.4
« on: June 19, 2017, 12:24:46 pm »
hello,
I am testing lazarus for a project and I found that heaptrc giving an error for me even on empty hello world program

Heap dump by heaptrc unit
1116 memory blocks allocated:1674034/1677096
1116 memory blocks freed: 1674034/1677096
0 unfreed memory blocks:0
True heap size: 688128(112 used in System startup)
True free heap:688016

seems 688016+112 = 688128... is it a real memory leak?

I am using lazarus-1.6.4-fpc-3.0.2-win32.exe

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: heaptrc error, lazarus 1.6.4
« Reply #1 on: June 19, 2017, 12:34:00 pm »
No, everything is okay.
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: heaptrc error, lazarus 1.6.4
« Reply #2 on: June 19, 2017, 12:35:22 pm »
Everything is OK. Heaptrace is a debugging tool. It also reports if nothing is wrong. It does not belong in release code, though.

May be you are confused by this?
True heap size: 688128(112 used in System startup)
True free heap:688016

In that case 688016 + 112 = 688128....
Specialize a type, not a var.

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
Re: heaptrc error, lazarus 1.6.4
« Reply #3 on: June 19, 2017, 12:44:47 pm »
Thanks!

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: heaptrc error, lazarus 1.6.4
« Reply #4 on: June 20, 2017, 01:35:11 pm »
You can use

Code: [Select]
  {$IF DECLARED(GlobalSkipIfNoLeaks)}
  // don't show empty heaptrc output
  GlobalSkipIfNoLeaks := True;
  {$ENDIF}

in yout LPR to disable the output of heaptrc if no memory leaks were detected. It works for recent FPC versions only (I don't remember in what stable version it was introduced, maybe it's only in trunk).

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: heaptrc error, lazarus 1.6.4
« Reply #5 on: June 20, 2017, 02:07:49 pm »
or something like this:

Code: Pascal  [Select][+][-]
  1. uses
  2.   SharedLogger, ipcchannel, filechannel, uniqueinstanceraw {...} ; // use multilog and UniqueInstance for convenience
  3.  
  4. const
  5.   LOG_FILENAME             = 'debug.log';
  6.   LOG_OLD_FILENAME         = 'debug.old.log';
  7.   LOG_START_CMD_FILENAME   = 'debug.run';
  8.   TRACE_FILENAME           = 'trace.log';
  9.   TRACE_OLD_FILENAME       = 'trace.old.log';
  10.   TRACE_START_CMD_FILENAME = 'trace.run';
  11.  
  12. begin
  13.   if InstanceRunning then
  14.   begin // Another application instance is already running
  15.     UseHeapTrace := false;
  16.     Exit;
  17.   end;
  18.   HaltOnError := false; // do not stop application on heap error
  19.  
  20.   if FileExists(TRACE_START_CMD_FILENAME) then
  21.   begin // send heap info to file instead of showing it on app exit
  22.     DeleteFile(TRACE_OLD_FILENAME);
  23.     RenameFile(TRACE_FILENAME, TRACE_OLD_FILENAME);
  24.     SetHeapTraceOutput(TRACE_FILENAME);
  25.   end
  26.   else
  27.     GlobalSkipIfNoLeaks := true; // when not tracing to file, we want trace dialog to show only if there are leaks
  28.  
  29.   if FileExists(LOG_START_CMD_FILENAME) then
  30.   begin // switch on file logging
  31.     DebugToFile := true;
  32.     DeleteFile(LOG_OLD_FILENAME);
  33.     RenameFile(LOG_FILENAME, LOG_OLD_FILENAME);
  34.     Logger.Channels.Add(TFileChannel.Create(LOG_FILENAME));
  35.   end;
  36.   Logger.Channels.Add(TIPCChannel.Create); // switch on ipc logging
  37.   Logger.Send('----------------------------------------------------');
  38.   Logger.SendHeapInfo('MyApplication heap on program start');
  39.  
  40.   Application.Initialize;
  41.   { ... create forms }
  42.   Application.Run;
  43.  
  44.   Logger.SendHeapInfo('Heap on program finish');
  45.   Logger.SendCallStack('Call stack');
  46. end.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: heaptrc error, lazarus 1.6.4
« Reply #6 on: June 20, 2017, 02:26:41 pm »
(I don't remember in what stable version it was introduced, maybe it's only in trunk).
Was added to fixes_3_0 on 31.5.2016
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

 

TinyPortal © 2005-2018