Pre loader

How to remove XySeriesData from memory?

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

Answered
0
0

In my application I remove lines from SciChartSurface, but Resharper still shows that data not removed from memory.
How completely remove from memory, that GC would collect it?

Edited:

I found smth strange, don’t even know if it’s my issue or not.
The structure shows what keeps my data alive.

using (sciChart.SuspendUpdates())
                {
                    for (var i = 0; i < pavadinimai.Count; i++)
                    {
                        if (pavadinimai[i] != null)
                        {
                            this.Dispatcher.Invoke((Action)(() =>
                            {
                                var sarasas = new List<Duomenys>(LinijuSarasas);
                                var line = sarasas.SingleOrDefault(p => p.Linija.Name == pavadinimai[i]);
                                try
                                {
                                        string pavadin = pavadinimai[i];
                                        var Ynauj = Ynauji[i].Select(p => (double)p).ToList();
                                        line.XyAsiesTaskai.Append(Xnauji, Ynauj);
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show(e.ToString());
                                }
                            }));
                        }
                    }
                }

And

var asis = asiesNr.ToString();
            using (sciChart.SuspendUpdates())
            {
                for (var i = 0; i < YdtSeries.Count; i++)
                {
                    if (pavadinimai[i] != null)
                    {
                        var dataSeries = MasyvasIXySeries(XdtSeries, YdtSeries[i], pavadinimai[i]);
                        var rnd = new Random().Next(0, 10);
                        var Fast = new FastLineRenderableSeries() { SeriesColor = spalvuMasyvas[i], DataSeries = dataSeries, Name = pavadinimai[i], YAxisId = asis, StrokeThickness = 1 };
                        PridetiLinijaPrieSaraso(dataSeries, asiesNr, asis, Fast, true, false);
                        sciChart.RenderableSeries.Add(Fast);
                        //sciChart.ZoomExtents();
                    }
                }
            }
  • You must to post comments
Best Answer
1
0

From the information you’ve given me so far,

if you call SciChartSurface.SuspendUpdates() it will return a token which holds a reference to the SciChartSurface. You must call .Dispose() on that token or the SciChartSurface will never be released from memory.

e.g.

var token = SciChartSurface.SuspendUpdates();
// ... 
token.Dispose();

or

using (SciChartSurface.SuspendUpdates())
{
    // ... 
}

if you are already doing this throughout your code, there is one more place where this type of memory leak could occur. If your SciChartSurface is never loaded in the visual tree, it can hold memory internally. To work around this, simply force OnLoad()

// Forces initialization. Also removes an ISuspendable used internally to SciChart
sciChartSurface.OnLoad()

Let me know if this helps.

Best regards,
Andrew

  • Elteros Projektai
    No, It didn't. I even tried to disable all .SuspendUpdates(), but it didn't change nothing.
  • Andrew Burnett-Thompson
    If you can email us a code sample we will investigate. We have no other reports of memory leaks related to ISuspendable that we know of.
  • Elteros Projektai
    I put OnLoad() at the inicialization and it started to work. I found out that ISuspendable holds chart even without data. Thank you very much for fast support.
  • Andrew Burnett-Thompson
    This suggests to me you have a chart which is never shown on screen (SciChartSurface.Loaded never fires). Just be sure this is intentional! Best regards, Andrew
  • butcher90
    Great answer! My code created SciChartSurface was not released and produced a memory leak. After calling OnLoad() the issue seems to be fixed!
  • 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