Problem with memory leaks FNC

Hello.

I work in Lazarus (ver.2.2.6 & ver.4.8, both 64bit) with FNC components.

While checking the program's operation, I noticed memory leaks. Since the program is too extensive, I created a very simple test application containing a form with a single TMSFNCHTMLText component (screenshot_1, screenshot_2). This simple application clearly illustrates the problem.

Memory leaks reported by Heaptrc is on screenshot_3 (only first screen).

Memory leaks do not occur without TMSFNCHTMLText component.

Because I am not sure how to solve this problem, so ask for help.

Greetings for TMS team!
Pawel

Hi Pawel,

Thank you for the clear report and test project. The leak is not in TTMSFNCHTMLText itself. It is in TMS FNC Core, which every FNC control uses. On LCL, the list of named colors (built when the unit LCLTMSFNCGraphicsTypes starts up) did not free its color objects at shutdown. That is the series of 16-byte blocks HeapTrc reports.

This is fixed in TMS FNC Core and will be included in the next update. If you want to apply it now, in LCLTMSFNCGraphicsTypes.pas, in the initialization section, add this line right after FColorLookup is created:

If HeapTrc still reports anything after this change, please send us the full report (not only the first screen) and we’ll look into it further.

Hi Pieter,

Thank you very much for fast response.
But in your answer i don't see what line should be added after FColorLookup is created; maybe it is some format problem of message, I don't know.

It looks this way:

Thank you in advance,
Pawel

Hi,

initialization
begin
  FColorLookup := TTMSFNCGraphicsColorList.Create{$IFNDEF LCLWEBLIB}([doOwnsValues]){$ENDIF};
  {$IFDEF LCLLIB}
  FColorLookup.OwnsObjects := True;
  {$ENDIF}

Anyway, latest version should have the fix included.

Hi Peter,

The situation improved significantly after the rows were added: the number of unfreed blocks decreased from 160 to 13.

I don't know how to add attachement, so paste the full report from Heaptrc (sorry for long text):

V:\TESTPROJ\FNC MemLeaks Test\test2.exe 
Heap dump by heaptrc unit of V:\TESTPROJ\FNC MemLeaks Test\test2.exe
3543 memory blocks allocated : 1218760/1229280
3530 memory blocks freed     : 1218552/1229072
13 unfreed memory blocks : 208
True heap size : 786432 (160 used in System startup)
True free heap : 783360
Should be : 783568
Call trace for block $00000000014B8C20 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8FDA  LCLTMSFNCGRAPHICSTYPES_$$_init$,  line 4075 of ../../lcltmsfncgraphicstypes.pas
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B8B40 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8FAD
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B7FE0 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8D64
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B7E20 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8D0A
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B7C60 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8CB0
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B6F40 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8A0D
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B6BC0 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8959
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B5340 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B846D
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B5260 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B8440
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B4E00 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B835F
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B2BE0 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B7C84
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B2A20 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B7C2A
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
Call trace for block $00000000014B25C0 size 16
  $0000000100012142
  $000000010000EFFA
  $00000001001B733D  CREATE,  line 3693 of ../../lcltmsfncgraphicstypes.pas
  $00000001001B7B4C
  $00000001000115FC
  $0000000100002EA1  $main,  line 19 of test2.lpr
  $0000000100003136
  $0000000100017B00
  $0000000100002E47
  $00007FFB996CCD87
  $00007FFB9AF2CAEC
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D
  $BAADF00DBAADF00D

Hope that will be useful for you .
If you find full solution, please let me know.

Greetings again, for you and all TMS team!

Pawel

Hi,

We saw duplicate entries, which were causing the additional unfreed blocks.

Next version will address this.

Now everything works without problems :).
Thank you very much!