TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Rund um die LCL und andere Komponenten
Antworten
Benutzeravatar
af0815
Lazarusforum e. V.
Beiträge: 7124
Registriert: So 7. Jan 2007, 10:20
OS, Lazarus, FPC: FPC fixes Lazarus fixes per fpcupdeluxe (win,linux,raspi)
CPU-Target: 32Bit (64Bit)
Wohnort: Burgenland
Kontaktdaten:

TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Beitrag von af0815 »

Ich suche mir einen Wolf für ein ganz spezielles Problem.
Ich habe einen Report in einem Datenmodul, dieser wird aus einem Frame her aufgerufen das ein Chart beinhaltet, das im Report verwendet wird. Mache ich einen Report so bleibt ein Speicherleck über, das aus dem Zusammenspiel Report und Chart zu stammen scheint.

Ohne dem Frame habe ich keine Speicherlecks. Erst wenn ich den Report aufrufe entsteht es.

Auf ein Minimum reduziertes Beispiel ist angehängt.

Lazarus 4.99 (rev main_4_99-3282-g77ab8459cf) FPC 3.2.2 x86_64-linux-gtk2
Heap dump by heaptrc unit of /home/..../Versuche/Forum/TAChart/LazReportTest/lazreportdemo
17837 memory blocks allocated : 69183073/69214232
17766 memory blocks freed : 59601236/59632352
71 unfreed memory blocks : 9581837
True heap size : 12222464
True free heap : 2625088
Should be : 2626952
Call trace for block $0000775ACB48A980 size 16
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
$000000000053F633 WNDPROC, line 5547 of include/wincontrol.inc
$000000000072CCF2 DELIVERMESSAGE, line 114 of lclmessageglue.pas
$00000000005FFFB0 DELIVERMESSAGE, line 3755 of gtk2/gtk2proc.inc
$000000000060B116 DODELIVERPAINTMESSAGE, line 27 of gtk2/gtk2callback.inc
$000000000060B1DA DELIVERPAINTMESSAGE, line 45 of gtk2/gtk2callback.inc
$000000000060B3F4 DELIVERGTKPAINTMESSAGE, line 111 of gtk2/gtk2callback.inc
$000000000060C172 GTKEXPOSEEVENT, line 623 of gtk2/gtk2callback.inc
$0000775ACAF46420
$0000775ACAD842FA
Call trace for block $0000775AC86E5F00 size 33
$00000000007B2096 OUTLINE, line 3856 of lr_class.pas
$00000000007B1923 WRAPLINE, line 3882 of lr_class.pas
$00000000007B16DD OUTMEMO, line 4016 of lr_class.pas
$00000000007B126D WRAPMEMO, line 4075 of lr_class.pas
$00000000007B392E DRAW, line 4456 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
$000000000053F633 WNDPROC, line 5547 of include/wincontrol.inc
$000000000072CCF2 DELIVERMESSAGE, line 114 of lclmessageglue.pas
$00000000005FFFB0 DELIVERMESSAGE, line 3755 of gtk2/gtk2proc.inc
$000000000060B116 DODELIVERPAINTMESSAGE, line 27 of gtk2/gtk2callback.inc
Call trace for block $0000775AC1345260 size 64
$00000000005716D1 CREATE, line 1510 of include/canvas.inc
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
$000000000053F633 WNDPROC, line 5547 of include/wincontrol.inc
$000000000072CCF2 DELIVERMESSAGE, line 114 of lclmessageglue.pas
Call trace for block $0000775AC976ECE0 size 264
$000000000056E8F9 DOCREATEDEFAULTBRUSH, line 352 of include/canvas.inc
$000000000068E4AD
$000000000068E0A5
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
Call trace for block $0000775AC13BFC00 size 144
$000000000056E8C9 DOCREATEDEFAULTPEN, line 347 of include/canvas.inc
$000000000068E40D
$000000000068E092
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
Call trace for block $0000775AC86C9800 size 32
$000000000068E07F
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
$000000000053F633 WNDPROC, line 5547 of include/wincontrol.inc
$000000000072CCF2 DELIVERMESSAGE, line 114 of lclmessageglue.pas
Call trace for block $0000775AC86C7C00 size 32
$000000000056E899 DOCREATEDEFAULTFONT, line 342 of include/canvas.inc
$000000000068E36D
$000000000068E07F
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
Call trace for block $0000775AC13DCF80 size 160
$000000000056E899 DOCREATEDEFAULTFONT, line 342 of include/canvas.inc
$000000000068E36D
$000000000068E07F
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
Call trace for block $0000775AC86C7900 size 24
$0000000000567A14 CREATE, line 23 of include/bitmapcanvas.inc
$00000000005649AC CREATECANVAS, line 325 of include/rasterimage.inc
$0000000000564970 GETCANVAS, line 317 of include/rasterimage.inc
$000000000056456A DRAW, line 259 of include/rasterimage.inc
$000000000056DE55 STRETCHDRAW, line 48 of include/canvas.inc
$00000000007B9DD7 DRAW, line 5814 of lr_class.pas
$00000000007C5C98 DRAW, line 9298 of lr_class.pas
$0000000000821CE5 PAINT, line 519 of lr_view.pas
$0000000000556D93 PAINTWINDOW, line 123 of include/customcontrol.inc
$000000000053E0F4 PAINTHANDLER, line 4982 of include/wincontrol.inc
$0000000000542502 WMPAINT, line 6943 of include/wincontrol.inc
$0000000000556CC6 WMPAINT, line 103 of include/customcontrol.inc
$000000000043352A
$000000000053F633 WNDPROC, line 5547 of include/wincontrol.inc
$000000000072CCF2 DELIVERMESSAGE, line 114 of lclmessageglue.pas
$00000000005FFFB0 DELIVERMESSAGE, line 3755 of gtk2/gtk2proc.inc
.....
Ooops: Lazarus 4.5 (rev lazarus_4_4-43-gb42c5e00a6) FPC 3.2.3 x86_64-linux-qt5
macht es nicht
Heap dump by heaptrc unit of /home/andi/data/pascal/Versuche/Forum/TAChart/LazReportTest/lazreportdemo
25090 memory blocks allocated : 1247237588/1247284456
25090 memory blocks freed : 1247237588/1247284456
0 unfreed memory blocks : 0
True heap size : 2064384
True free heap : 2064384
Dateianhänge
lazreportdemo.zip
(6.54 KiB) 300-mal heruntergeladen
Blöd kann man ruhig sein, nur zu Helfen muss man sich wissen (oder nachsehen in LazInfos/LazSnippets).

Benutzeravatar
lcb-User
Beiträge: 61
Registriert: Di 15. Jul 2014, 13:18
OS, Lazarus, FPC: Linux Mint 22.3 Cinnamon Lazarus 4.5 (rev lazarus_4_4-90-g89a402ebc1) FPC 3.2.2
CPU-Target: 64Bit(win32Bit)
Wohnort: München
Kontaktdaten:

Re: TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Beitrag von lcb-User »

Hallo,

Ich sehe nichts :o

Code: Alles auswählen

./lazreportdemo 
Heap dump by heaptrc unit of /home/lcb/lzProject/LazarusForum/af0815/datenmodul-speicherleck/lazreportdemo
15449 memory blocks allocated : 44851547/44877352
15449 memory blocks freed     : 44851547/44877352
0 unfreed memory blocks : 0
True heap size : 2129920
True free heap : 2129920
Oder übersehe ich da was :?

Lazarus 4.5 (rev lazarus_4_4-90-g89a402ebc1) FPC 3.2.2 x86_64-linux-gtk2
Sonnige Grüße
Bibsi


Traue keiner Statistik die du nicht selbst gefälscht hast (Sir Winston Churchill 1874 - 1965)
Linux Mint 22.2 Cinnamon 6.4.8, Kernel 6.8.0-79-generic
Lazarus 4.3 (rev lazarus_4_2-11-g4374647103) FPC 3.2.2 x86_64-linux-gtk2

wp_xyz
Beiträge: 5368
Registriert: Fr 8. Apr 2011, 09:01

Re: TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Beitrag von wp_xyz »

Das Speicherleck sehe ich auch, sobald man den "Show Report" Button angeklickt hat.

Beim Durchscrollen durch LR_Class (ich habe von LazReport keine Ahnung...), sind mir ein paar Stellen aufgefallen. Es gibt da eine HookList (Type TFPList) - bei FPList ist immer die Gefahr, dass man darin Objekte speichert, die man eigentlich freigeben sollte... Genauso TFrPages und TFrEMFPages und Page.Objects.

Kannst du mal einen Report machen, der gar keinen TAChart enthält, sondern nur ein Label (oder vielleicht sogar gar nichts) - gibt es das speicherleck da immer noch?

Benutzeravatar
af0815
Lazarusforum e. V.
Beiträge: 7124
Registriert: So 7. Jan 2007, 10:20
OS, Lazarus, FPC: FPC fixes Lazarus fixes per fpcupdeluxe (win,linux,raspi)
CPU-Target: 32Bit (64Bit)
Wohnort: Burgenland
Kontaktdaten:

Re: TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Beitrag von af0815 »

wp_xyz hat geschrieben: So 8. Feb 2026, 20:21 Kannst du mal einen Report machen, der gar keinen TAChart enthält, sondern nur ein Label (oder vielleicht sogar gar nichts) - gibt es das speicherleck da immer noch?
Es reicht, wenn ich das FChartToPrint.Draw auskommentiere. Dann gibt es also bei gtk2 jede Menge Leaks in der lr_class.pas. Dort ist also der Hund begraben. Das arme TAChart kann da nichts dafür.

Stand: Projekt Immer als QT5 kompiliert
Lazarus 4.5 (rev lazarus_4_4-43-gb42c5e00a6) FPC 3.2.3 x86_64-linux-qt5 -> keine Speicherlecks
Lazarus 4.99 (rev main_4_99-3282-g77ab8459cf) FPC 3.2.2 x86_64-linux-gtk2 -> Speicherlecks
Lazarus 4.99 (rev main_4_99-3282-g77ab8459cf) FPC 3.2.2 x86_64-linux-qt5 -> Speicherlecks

Und es ist egal, ob man den Report statisch oder dynamisch erstellt.

Edit:
ich habe ein Diff der Versionen gemacht und bin auf eine (unlogische) Stelle gestossen (lr_class.pas Zeile 7593):
Alt:

Code: Alles auswählen

procedure TfrPage.Clear;
begin
  while Objects.Count > 0 do
    Delete(0);
end;  
Neu:

Code: Alles auswählen

procedure TfrPage.Clear;
begin
  while Objects.Count > 0 do
    Objects.Delete(0);
end;  
Ändere ich das zuück, geht es plötzlich ohne Speicherleck. Ganz komisch die Stelle.
Blöd kann man ruhig sein, nur zu Helfen muss man sich wissen (oder nachsehen in LazInfos/LazSnippets).

Benutzeravatar
af0815
Lazarusforum e. V.
Beiträge: 7124
Registriert: So 7. Jan 2007, 10:20
OS, Lazarus, FPC: FPC fixes Lazarus fixes per fpcupdeluxe (win,linux,raspi)
CPU-Target: 32Bit (64Bit)
Wohnort: Burgenland
Kontaktdaten:

Re: TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Beitrag von af0815 »

af0815 hat geschrieben: Mo 9. Feb 2026, 11:35
wp_xyz hat geschrieben: So 8. Feb 2026, 20:21 Kannst du mal einen Report machen, der gar keinen TAChart enthält, sondern nur ein Label (oder vielleicht sogar gar nichts) - gibt es das speicherleck da immer noch?
Es reicht, wenn ich das FChartToPrint.Draw auskommentiere. Dann gibt es also bei gtk2 jede Menge Leaks in der lr_class.pas. Dort ist also der Hund begraben. Das arme TAChart kann da nichts dafür.

Stand: Projekt Immer als QT5 kompiliert
Lazarus 4.5 (rev lazarus_4_4-43-gb42c5e00a6) FPC 3.2.3 x86_64-linux-qt5 -> keine Speicherlecks
Lazarus 4.99 (rev main_4_99-3282-g77ab8459cf) FPC 3.2.2 x86_64-linux-gtk2 -> Speicherlecks
Lazarus 4.99 (rev main_4_99-3282-g77ab8459cf) FPC 3.2.2 x86_64-linux-qt5 -> Speicherlecks

Und es ist egal, ob man den Report statisch oder dynamisch erstellt.

Edit:
ich habe ein Diff der Versionen gemacht und bin auf eine (unlogische) Stelle gestossen (lr_class.pas Zeile 7593):
Alt:

Code: Alles auswählen

procedure TfrPage.Clear;
begin
  while Objects.Count > 0 do
    Delete(0);
end;  
Neu:

Code: Alles auswählen

procedure TfrPage.Clear;
begin
  while Objects.Count > 0 do
    Objects.Delete(0);
end;  
Ändere ich das zuück, geht es plötzlich ohne Speicherleck. Ganz komisch die Stelle.
https://gitlab.com/freepascal.org/lazar ... ddd8256a80
Blöd kann man ruhig sein, nur zu Helfen muss man sich wissen (oder nachsehen in LazInfos/LazSnippets).

Benutzeravatar
Zvoni
Beiträge: 533
Registriert: Fr 5. Jul 2024, 08:26
OS, Lazarus, FPC: Windoof 10 Pro (Laz/FPC fixes)
CPU-Target: 64Bit
Wohnort: BW

Re: TAChart in Frame und LazReport im Datenmodul - Speicherlecks

Beitrag von Zvoni »

Und wenn man auch noch die folgende Prozedur sich anschaut, sieht man dass DORT das "angeblich" fehlende "Objects.Delete(0)" ausgeführt wird, weil aus aus der Clear-Prozedur eh immer 0 als Index übergeben wird

Code: Alles auswählen

procedure TfrPage.Clear;
begin
  while Objects.Count > 0 do
    Delete(0);
end;

procedure TfrPage.Delete(Index: Integer);
begin
  if not (doChildComponent in TfrView(Objects[Index]).FDesignOptions) then
    TfrView(Objects[Index]).Free;
  Objects.Delete(Index);
end;
mMn ist/war der Patch nonsense.
Heisst: Das Speicher-Leck entstand dadurch, dass diese Zeilen NICHT ausgeführt wurden (eben WEIL Delete(0) nicht mehr aufgerufen wurde):

Code: Alles auswählen

if not (doChildComponent in TfrView(Objects[Index]).FDesignOptions) then
    TfrView(Objects[Index]).Free;
Ein System sie alle zu knechten, ein Code sie alle zu finden,
Eine IDE sie ins Dunkel zu treiben, und an das Framework ewig zu binden,
Im Lande Redmond, wo die Windows drohn.

Antworten