0

I've been trying to find a memory leak on iOS and i'm 99% it is either in a TScrollBox or in a TChart. The action that leads to the crash is simple scrolling back and forth across the TChart. The app behaves well in Win32 and memory useage is stable.

The crash cause on iOS is EXC_RESOURCE -> myappname[5548] exceeded mem limit: ActiveHard 1400MB (fatal) per Xcode Console.

To exclude my spaghetti code as the culprit i created a simple project to reproduce the error and it crashes too. Below are snips from the Xcode Console output. I get tons of assertions, then the Received memory warning, then the iOS kernal kills my app (Project1).

default 20:28:26.180333 -0500 assertiond [Project1:7693] Activate assertion: <BKProcessAssertion: 0x12b0102c0; "com.apple.UIKit.KeyboardManagement.message" (finishTask:180s); id:…8EA7F5E94DD5> default 20:28:26.180542 -0500 assertiond [Project1:7693] Setting jetsam priority to 10 [0x10108] default 20:28:26.182151 -0500 assertiond [Project1:7693] Deactivate assertion: <BKProcessAssertion: 0x12b0102c0; "com.apple.UIKit.KeyboardManagement.message" (finishTask:180s); id:…8EA7F5E94DD5> default 20:28:26.182312 -0500 assertiond [Project1:7693] Setting jetsam priority to 10 [0x10100] default 20:28:26.183307 -0500 assertiond [Project1:7693] Remove assertion: <BKProcessAssertion: 0x12b0102c0; "com.apple.UIKit.KeyboardManagement.message" (finishTask:180s); id:…8EA7F5E94DD5> default 20:28:32.609723 -0500 Project1 Received memory warning.

Then a short time later i see the following console message:

default 20:28:45.881914 -0500 kernel EXC_RESOURCE -> Project1[7693] exceeded mem limit: ActiveHard 1400 MB (fatal).

My crash test app is a simple Firemonkey app built in C++ Builder 10.3.2.

A) Put a TPanel on the form (Panel1).

B) Put a TScrollBox on Panel1 (ScrollBox1). Set its align to Contents.

C) Put a TLayout on ScrollBox1 (Layout1). Set its align to None. Set its width to 2100.

D) Put a TChart on Layout1. Set its height to 200, width 7300. Set its align to None.

E) Add a TToolBar to Form1 and put a TButton on it.

F) Then put this code in the TButton's click event:

Form1->Layout1->Position->X = 0;
Form1->ChartTest->Position->Y = 0;
Form1->ChartTest->Position->X = 0;

TLineSeries *series1 = new TLineSeries(Form1);
TLineSeries *series2 = new TLineSeries(Form1);
TLineSeries *series3 = new TLineSeries(Form1);
TLineSeries *series4 = new TLineSeries(Form1);

series1->Color = claBlue; 
series2->Color = claRed;
series3->Color = claBlueviolet;
series4->Color = claAqua;

double x, y;
for (int i = 0; i < 1000; i++) {
 x = i;
 y = Random(5000);
 series1->AddXY(x,y);
 y = Random(5000);
 series2->AddXY(x,y);
 y = Random(5000);
 series3->AddXY(x,y);
 y = Random(5000);
 series4->AddXY(x,y);
}

Form1->ChartTest->AddSeries(series1);
Form1->ChartTest->AddSeries(series2);
Form1->ChartTest->AddSeries(series3);
Form1->ChartTest->AddSeries(series4);

G) And now, with your iOS device connected to your mac and Xcode Console open, filter the Console output on "Project1" if that is what you named it. Then run the app and scroll backwards/forwards and/or up/down (also change orientation if you want back and forth). You will see tons of assertions. Eventually (takes around 2-3 minutes of this harassment to make it crash) it will eat up enough memory that it crashes.

I think the memory leak is in the TeeChart most likely, maybe in the TScrollBox?

thanks, russ

Spektre
  • 49,595
  • 11
  • 110
  • 380
relayman357
  • 793
  • 1
  • 6
  • 30
  • 1
    I do not code in FMX but I see no `delete series1;` ... so unless the `TChart` is releasing it on its own or do not make own copy (which I doubt) it would memory leak ... but crash would make more sense if you got this in the Scrolling event ... so check for forgotten deletes ... can you post MCVE ? (cpp,hpp,dfm) of the minimal app crashing like this ... You might be overlooking something trivial (common for authors of the code due to memory sight, brain sees what it remembers should be there instead of what it is in real) – Spektre Sep 04 '19 at 08:08
  • Thanks Spektre. I put my test project (Project1) here: http://relayman.org/temp/_tmpp/ – relayman357 Sep 04 '19 at 13:30
  • 1
    Hmm I see nothing suspicious appart those missing deletes so it might be a compiler/framework bug. Try to add the missing deletes if the situation changes ... – Spektre Sep 04 '19 at 17:18
  • I added the `delete` lines and it made no difference. I experimented with a `TVertScrollBox` too but same result (memory crash). It is a descendent of TScrollBox so no surprise there. I'm trying to figure a way to get my scrolling effect without using a `TScrollBox` right now. – relayman357 Sep 04 '19 at 17:29
  • I tested by getting rid of the `TChart` and just put a bunch of `TRectangles` on the ScrollBox. I can scroll until my fingers fall off and no problem. So, i'm thinking some interaction between the `TScrollBox` and the `TChart` must be happening? In my original app (not the test app linked above) I just now got rid of the `TScrollBox` altogether and the memory crash problem is gone. Now i'm working on custom code to scroll my `TLaytout` up and down without using scrollbox.... – relayman357 Sep 04 '19 at 17:54

1 Answers1

0

The memory leak is in the TChart. I created another simple project with no scrollbox and i added a timer that moves the TChart up and down every 0.1 seconds. After 2-3 minutes it crashes on memory error on iOS with no user input after clicking Button1 to start things off. This crash occurs with no scrolling or any interaction - just the chart wiggling around.

Testing the app on Win32 works fine - memory is stable and not growing.

So, i'm hoping there is something obvious in how i create the chart that is the deficiency - i really don't want to abandon ship as Steema charts are so flexible. I've also posted to the Steema forum's but due to low volume there i'm posting here too.

Any ideas? Note i'm also using a licensed version of TeeChart Standard VCL/FMX released May 30, 2019 - Build 2019.27.190530. I also ran a test case where the chart is stationary (no user input and no timer event moving the chart around) and no crash. It has to do with the chart being rejiggered somehow. I tried Form1->ChartTest->AutoRepaint = false; but had no effect. The zipped test project is here: Project1a

thanks, russ

UPDATE: The memory leak bug is present in TeeChart Standard build 2019.27.190530 but is not present in the free/lite version that comes stock with Rad Studio 10.3.2 as of now (version v2016.17.160129).

Community
  • 1
  • 1
relayman357
  • 793
  • 1
  • 6
  • 30
  • 1
    If you're using a licensed version of TeeChart Standard, you should be reporting this issue directly to the vendor. If there is in fact a bug leading to a memory leak, the vendor would be the only one who can correct it. – Ken White Sep 05 '19 at 00:21
  • Agree and i've done that. I'm in process of uninstalling Rad Studio and the licensed version of TeeChart Standard to reinstall fresh everything and see if the version that comes with Rad Studio has same problem. – relayman357 Sep 05 '19 at 00:38
  • 1
    The version with RAD Studio would be based on a compiled version of TeeChart Standard, so uninstalling/reinstalling is probably not going to accomplish anything. You don't have to totally uninstall, anyway. You can just use a different IDE profile without your version of the component installed. See https://stackoverflow.com/a/20432742/62576 – Ken White Sep 05 '19 at 00:41
  • Ok, that is amaizing (start with different profile). Thanks Ken. Also, just finished testing with the version of TeeChart Standard that comes stock with Rad Studio 10.3.2 and it works fine (`TeeChart Lite v2016.17.160129`). No kidding. Both my test projects and my original app run fine with no memory leak problem! Looks like a later build of `TeeChart Standard` introduced the issue. I'll report that to Steema. Any reason to let Embarcadero know too so they don't upgrade to leaky version in later release? – relayman357 Sep 05 '19 at 02:00
  • 1
    You could file a bug report to let them know; it couldn't hurt, right? :-) – Ken White Sep 05 '19 at 02:20
  • Done. Reported to Embarcadero as [RSP-26108](https://quality.embarcadero.com/browse/RSP-26108). Here is link to issue reported on Steema forums - [memory leak on iOS with teechart](https://www.steema.com/support/viewtopic.php?f=17&t=17230), and here is link to [bug report](http://bugs.teechart.net/show_bug.cgi?id=2236) at Steema. – relayman357 Sep 10 '19 at 23:36