Pre loader

Memory leak in suspedUpdates() / resumeUpdates()

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

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.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies