Forum > TAChart
[Solved] Memory leaks when using TChart
Wilko500:
MacOs Sequoia 15.6.1
My Inverter logging app is progressing well but . . . under testing I have found a significant memory problem, unlike anything I have encountered yet, "Application paused Out of Application memory". When application fails MacOs reports application memory approx 140Gb! and that is roughly the amount of free disk space on my Mac.
Do I have memory leaks? Yes, 17 unfreed blocks. Used debug mode and managed to get this down to 9 blocks. The remainder are still present but the limited line info points toward stuff that is not in my code. I began to compare the failing program with a prototype that does not have the unfreed blocks. The main difference is Charts so that is where I started my investigation.
I created a new project containing a single TChart with a single LineSeries. Compile. Run from terminal and on exit 3 unfreed blocks, 2 for the chart, 1 for the LineSeries. Adding a second chart does not increase the unfired blocks. First part of the dump is below.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Heap dump by heaptrc unit of /Volumes/MacHD-SSD-Data/LocBucket/FpLazStuff/ZTest/project12473 memory blocks allocated : 1238099/12419922470 memory blocks freed : 1237971/12418643 unfreed memory blocks : 128True heap size : 983040 (96 used in System startup)True free heap : 982176Should be : 982240Call trace for block $00000001EA773E00 size 48 $000000010FE9DFE1 $000000010FD2A496 $000000010FD19B0A $000000010FD1A14A $000000010FD1AEC0 $000000010FD1E9DA $000000010FD1EC89 $000000010FF75409 $000000010FF3F9A5 $000000010FF8B2B2 $000000010FF7FA94 $000000010FF0AE9F $000000010FF0D334 $000000010FF049E1 $000000010FF0177E $000000010FF044ADI don't recall seeing anything in the documentation about needing to free charts or series. Perhaps someone can verify my findings or explain what is happening? I don't have access to Windoze to test but I do wonder if this is a Mac thing
wp:
I have a VM with a Mac OS 10.14 Mojave and can confirm the issue there. I cannot confirm it, however, on Windows, Linux gtk2, gtk3, qt5, qt6. Therefore I am rather sure that the memory leak originates somewhere outside TAChart.
On the mac-VM is switched the chart to be invisible (Chart1.Visible := false) - no more memory leaks. This seems to indicate that the memory leak somehow has something to do with painting.
Wilko500:
Thank you. I confirm you setting Chart1.Visible:=false does prevent the memory leak. That is very interesting because I have in the past seen a small test program with memory leaks with no user code involved but in that case not a chart but buttons, edits and maybe a checkbox. I'll see if I still have that test program, it might have the same cause, maybe a bug??
I doubt if this is the cause of my Application Out Of Memory issue so more test required there.
wp:
Played a bit in Laz/cocoa to find memory leaks. Here is a very simple one:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormPaint(Sender: TObject);begin Canvas.TextOut(0, 0, 'Test');end;Can you confirm this? If yes, I'll file a bug report.
Wilko500:
Yes, I confirm your test. On program exit I get
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---634 memory blocks allocated : 1101756/1102248632 memory blocks freed : 1101676/11021682 unfreed memory blocks : 80True heap size : 1769472 (96 used in System startup)True free heap : 1768864Should be : 1768912Output truncated by me
Navigation
[0] Message Index
[#] Next page