Recent

Author Topic: TTrayIcon, memory leak  (Read 5229 times)

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
TTrayIcon, memory leak
« on: November 12, 2017, 11:41:59 pm »
The LCL component, TTrayIcon has a significant memory leak on the Mac (but not Linux or Windows). My testing has been with 1.8rc4 and its very easily reproduced and it would seem likely that any app using the TrayIcon will be affected.

Put a trayIcon on a blank form, call TrayIcon1.show from the form's OnShow event handler and  turn on HeapTrc from project options. Compile and run from command line (so you see Heaptrc report). Its not pretty.

I have not tested against RC5, but I'd expect the problem will be there too.

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: TTrayIcon, memory leak
« Reply #1 on: November 24, 2017, 08:48:55 pm »
Sorry for the late response, but you might be on to something.
I use the Tray Icon in one of my Mac applications and the used memory definitely seems to be increasing - just not sure if Tray Icon is causing this.
I've never worked with HeapTrc, and hint on how to work with that?

traumschule

  • Newbie
  • Posts: 3
Re: TTrayIcon, memory leak
« Reply #2 on: November 29, 2017, 09:05:31 pm »
you need compile the project with -gh
in Lazarus: Project -> Project Optiona -> Compiler Options -> Debugging -> Other Debugging Info
https://www.freepascal.org/docs-html/rtl/heaptrc/usage.html
http://wiki.freepascal.org/leakview

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TTrayIcon, memory leak
« Reply #3 on: December 04, 2017, 03:22:24 am »
Attempting to trace this memory leak but not finding heattrc very helpful. On other platforms, I have found it shows me line numbers where things go wrong but not here -
Code: [Select]
....
Heap dump by heaptrc unit
3581 memory blocks allocated : 1969651/1983640
3573 memory blocks freed     : 1969499/1983464
8 unfreed memory blocks : 152
True heap size : 884736 (48 used in System startup)
True free heap : 883920
Should be : 884000
Call trace for block $009300A0 size 16
  $002BBB49
  $002401AC
...

I have (obviously) turned on heaptrc  and -gl in project options, even tried adding lineinfo to users clause.
I am not sure if this problem is due to -
  • I'm using OSX
  • I'm looking at a problem in LCL

I have tried making some arbitory changes in what I think are the relevent LCL files to force a recompile but still no line numbers !
This problem is unique to OSX so cannot debug on other platform.

Any suggestions please ?
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TTrayIcon, memory leak
« Reply #4 on: December 04, 2017, 05:48:14 am »
Further clarification, the heaptrc issue is Mac related.

A deliberate memory leak in my test code is also reported without naming the file or any line numbers. Does this mean that heaptrc cannot be used on the Mac or is there some way I relate  block addresses to the source code ?

I know there is no point in logging a HeapTrc bug in the tracker.

David 
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: TTrayIcon, memory leak
« Reply #5 on: December 04, 2017, 08:14:40 am »
You need to include proper debug info into FPC RTL/packages and Lazarus LCL. First recompile FPC with debug info enabled and then do same for Lazarus.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TTrayIcon, memory leak
« Reply #6 on: December 04, 2017, 09:01:34 am »
Oh, wow ! thanks Cyrax
I am using 1.8rc4 installed from

https://sourceforge.net/projects/lazarus/files/Lazarus%20Mac%20OS%20X%20i386/Lazarus%201.8.0RC4/

Are you saying that these would not have debug info compiled in ?   Windows and Linux ones from same tree do have all necessary debug info.

Thanks for your response !

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TTrayIcon, memory leak
« Reply #7 on: December 04, 2017, 09:43:35 am »
The FPC binaries (RTL etc.) shipped with Lazarus do not have debug info, so  their download size is reasonable, and so that the compiler itself loads and executes as quickly as possible.
It is the FPC libraries that you need to recompile to include debug information.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TTrayIcon, memory leak
« Reply #8 on: December 04, 2017, 10:54:49 am »
OK, thanks. You did note my comment that even a deliberate memory leak in my code, project1, does not get line numbers ?  As simple as
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.     Ptr : ^longint;
  4. begin
  5.     new(Ptr);
  6.     new(Ptr);
  7. end;

Similarly, a simple divide by zero exception does not get a line number...
       
Anyway, I must admit I am struggling here, I would be very grateful if you could comment on what I understand I need do.

I do have fpcsrc installed, its in /usr/local/share/ so, I need recompile with -gl, find the problem (yeah, sure) and then recompile again without that switch so that my normally resulting binaries are not bloated. Or should I compile a different tree, one with debug symbols and switch between ?

https://freepascal.org/docs-html/current/prog/progsu219.html#x331-347000F.4.1 says I need to compile -

System Unit - /usr/local/share/fpcsrc/rtl/macos/system.pp
Strings Unit - /usr/local/share/fpcsrc/rtl/inc/strings.pp
Doc unit - /local/share/fpcsrc/rtl/macos/dos.pp
Objects Unit - /usr/local/share/fpcsrc/packages/rtl-extra/src/inc/objects.pp

Same document suggests a command line using ppc386, as I’m using cocoa, thats all I’d need.

Or can I use -
/local/share/fpcsrc/rtl/darwin/Makefile.fpc and define DEBUG as per
https://freepascal.org/docs-html/current/prog/progsu206.html#x311-327000E.6.2
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018