SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components



I have a very simple iOS project in XCode 13 which uses Swift. The project has a tab bar controller with two tabs. The first tab brings up a sample home screen and the second tab initializes a blank SciChart graph.

I want to eventually be able to sometimes change what data is shown on the graph (via Bluetooth), and therefore I want to run my graph code every time the tab for the graph is selected. I put all my code for SciChart inside:

override func viewWillAppear(_ animated: Bool)

and this almost works fine, but declaring

let surface = SCIChartSurface() inside of override func viewWillAppear(_ animated: Bool)

seems to be causing some sort of memory leak. Switching between tabs often causes my app to crash and XCode reports the following error message: “Terminated due to memory issue”

Is there a better way to initialize my graph to prevent this memory leak? Or is there way to flush the “surface” variable from memory when transitioning between tabs to prevent this memory issue from occurring?

My small sample project is available here which demonstrates the memory leak when switching between the home screen tab and graph tab:

Any help greatly appreciated, thanks!

  • You must to post comments

Hi, Andrew.

In your case, I would do it this way:

  1. In “viewDidLoad” Initialize your surface and add it as a subview once
  2. In “viewWillAppear” init your chart, add axes, series, etc
  3. In “viewDidDisappear” clear everything, that has been added to the chart, like this:


I hope that will help.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.