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.
- MIha Rozina asked 6 years ago
- You must login to post comments
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
- Yura Khariton answered 6 years ago
-
Ah I have missed that. Thank you for your help!
- You must login to post comments
Please login first to submit.