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

0
0

Hello.

I have found out that calling suspendUpdate() and resumeUpdate() on a SciChartSurface object allocates memory that is never released. The allocations get bigger with more data in the chart.

I have created an empty Android project. I have added a SciChartSurface and a Button. Pressing the button suspends and resumes updates. You can then see in the Android Monitor that after each press of the button the memory consumption of the app increases. Since the chart is empty the allocations are very small but still noticeable. I have attached the zip of the example project.

Kotlin code of the Activity in the project:

class MainActivity : AppCompatActivity()
{
    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val layout = findViewById(R.id.layout) as ConstraintLayout

        val chartSurface = SciChartSurface(this)
        layout.addView(chartSurface)

        val button = findViewById(R.id.button) as Button
        button.setOnClickListener {
            val suspender = chartSurface.suspendUpdates()
            chartSurface.resumeUpdates(suspender)
        }
    }
}

I

P.S.:
I have tried to open a priority ticket, but I got the following error:

We encountered a problem (cross-site request forgery detected); please try again
Sorry, we encountered a problem (invalid department). Please start over.

Version
2.0.0.1884
Attachments
  • You must to post comments
0
0

Hi Miha,

I believe this happens because of incorrect using of UpdateSuspender API. To prevent memory leaking you need to call dispose() or close() method on suspender instance:

val suspender = chartSurface.suspendUpdates()
suspender.dispose()

Also UpdateSuspender implements AutoClosable interface which allows you to use try-with-resources statement and ensures that suspender will be disposed and there will be no memory leaks. Also you can use helper method provided by UpdateSuspender class which we use in our examples ( it uses try-with-resources under the hood ):

UpdateSuspender.using(surface, {
    // do something while surface is suspended
})

Hope this will help you!

Best regards,
Yura

  • MIha Rozina
    Ah I have missed that. Thank you for your help!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

SciChart WPF v5 is here! Use the discount code SCICHARTV5 to get 15% off WPF Charts until December 31st!Read More
+