Pre loader

Tag: memory leak

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 votes
4k views

Hi.
I’m in process optimizing my app.
I’m using Objective-c.

I’d found some memory leaking issues and successfully fixed some of that.

A first issue was about ‘renderableSeries’ under ‘SCIChartSurfaceView’.
If you set class of UIView as ‘SCIChartSurfaceView’ in interface builder and make outlet without setting ‘strong’ or ‘weak’ in .m file,
It never get released automatically and will stay retained on memory.
For me, it caused about 90MB of memory leaking.
But I could solve this issue manually by putting -(void)clear; method of renderableSeries in viewWillDisappear method.

Another issue is about ‘SCIDateTimeDeltaCalculator’ and ‘SCINumericDeltaCalculator’.
It causes about 50MB of memory leaking.
But problem is, I couldn’t find neither where it’s been called nor how I release this manually.

I will be waiting for your answer.

Thanks.

+)
(lldb) po SciChartVersionNumber
0x3ff0000000000000

(lldb) po SciChartVersionString
0x474f525029232840

I wanted to know what version I’m using.. but i couldn’t know… what version am i using..?

1 vote
1k views

Hello,

I found an issue with very high memory usage by the application. after some tests I found the problem and moved it to a separate example(https://codepen.io/PodaRocheK/pen/PoVmzvP?editors=0011). Please check this code and observe the memory usage on this page. With prolonged use (after 10 minutes), it is clear that more and more memory is used. After hours, the memory used may already be more than several gigabytes. Tell me what the problem is, maybe I’m doing something wrong. Maybe I’m somehow storing old data incorrectly or adding it incorrectly.

This example is not a working example, it has been sped up in order to quickly identify the problem. In our example, an unnecessary data update will occur once every few seconds and after a night of inactivity, the entire page will die. Please tell me what the problem is.

Thank you!

0 votes
2k views

Hi,

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: https://drive.google.com/file/d/1mz88R3kKvoPqSGxFzohoHGDkseSwgHPh/view?usp=sharing

Any help greatly appreciated, thanks!

0 votes
6k views

It seems like a memory leak of sciChartSurface. After call Dispose(), some sciChartSurfaces are also refrenced by MouseManager and can’t release.

I also use ants memory profiler, but this web page can’t upload images and attachments, it alerts Forbidden!

The leak instance reference chain is:
MouseManager.I -> Dictionary<string,IList<Mouse.IReceiveMouseEvents>> -> SciChart.Core.Utility.Mouse.IReceiveMouseEvents[] -> SciChart.Charting.ChartModifiers.ModifierGroup -> SciChart.Charting.Visuals.SciChartSurface .

Below is the key code:

>

    private SciChartSurface sciTickPriceChartSurface;
    private FastLineRenderableSeries lastPriceLineRenderableSeries;
    private SciChartSurface sciTickVolumeChartSurface;
    private FastLineRenderableSeries volumeLineRenderableSeries;

    private void LoadSciTickCharts()
    {
        // set sciTickPriceChartSurface xAxis
        var nowDateTime = DateTime.Now; 
        var todayDate = nowDateTime.Date;

        // set sciTickPriceChartSurface
        sciTickPriceChartSurface = new SciChartSurface();
        sciTickPriceChartSurface.ViewportManager = new TickChartViewportManager(todayDate);

        var priceChartXAxis = new DiscontinuousDateTimeAxis
        {
            DrawLabels = false,
            MajorDelta = new TimeSpan(1, 0, 0),
            MinorDelta = new TimeSpan(0,12,0),
            MinimalZoomConstrain = new TimeSpan(1,0,0),
            AutoTicks = false,
            DrawMajorGridLines = true,
            DrawMinorGridLines = false,
            AutoRange = AutoRange.Never,
            LabelProvider = new TickDateTimeAxisLabelProvider(),
            //Calendar = new LSECalendar(), 
            VisibleRange = new DateRange(nowDateTime - new TimeSpan(1,0,0), nowDateTime + new TimeSpan(3,0,0)),
        };

        sciTickPriceChartSurface.XAxes.Add(priceChartXAxis);

        // set sciTickPriceChartSurface yAxis
        var priceYAxis = new NumericAxis
        {
            DrawMajorGridLines = true,
            DrawMinorGridLines = false,
            AutoRange = AutoRange.Always,
            GrowBy = new DoubleRange(0.2, 0.2)
        };
        sciTickPriceChartSurface.YAxes.Add(priceYAxis);

        // lastPriceLineSeries
        lastPriceLineRenderableSeries = new FastLineRenderableSeries
        {
            Stroke = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF),
            StrokeThickness = 1,
            DataSeries = new XyDataSeries<DateTime, double>(),
        };
        sciTickPriceChartSurface.RenderableSeries.Add(lastPriceLineRenderableSeries);
        CursorModifier.SetSnapToSeries(lastPriceLineRenderableSeries, true);

        // sciTickVolumeChartSurface
        sciTickVolumeChartSurface = new SciChartSurface();

        // set sciTickVolumeChartSurface yAxis
        var volumeYAxis = new NumericAxis
        {
            DrawMajorGridLines = true,
            DrawMinorGridLines = false,
            AutoRange = AutoRange.Always,
            GrowBy = new DoubleRange(0, 0)
        };
        sciTickVolumeChartSurface.YAxes.Add(volumeYAxis);

        var volumeChartXAxis = new DiscontinuousDateTimeAxis
        {
            DrawLabels = true,
            MajorDelta = new TimeSpan(1, 0, 0),
            MinorDelta = new TimeSpan(0, 12, 0),
            MinimalZoomConstrain = new TimeSpan(1, 0, 0),
            AutoTicks = false,
            DrawMajorGridLines = true,
            DrawMinorGridLines = false,
            AutoRange = AutoRange.Never,
            LabelProvider = new TickDateTimeAxisLabelProvider(),
            //Calendar = new LSECalendar()
        };
        sciTickVolumeChartSurface.XAxes.Add(volumeChartXAxis);

        // Bind the VisibleRange of chart2.XAxis.VisibleRange to chart1.XAxis.VisibleRange TwoWay
        var xAxisVisibleRangeBinding = new Binding("VisibleRange")
        {
            Source = priceChartXAxis,
            Mode = BindingMode.TwoWay,
        };
        BindingOperations.SetBinding(volumeChartXAxis, SciChart.Charting.Visuals.Axes.AxisBase.VisibleRangeProperty, xAxisVisibleRangeBinding);

        // volumeLineSeries
        volumeLineRenderableSeries = new FastLineRenderableSeries
        {
            Stroke = Color.FromArgb(0xFF, 0x0, 0xFF, 0xFF),
            StrokeThickness = 1,
            DataSeries = new XyDataSeries<DateTime, long>(),
        };
        sciTickVolumeChartSurface.RenderableSeries.Add(volumeLineRenderableSeries);
        CursorModifier.SetSnapToSeries(volumeLineRenderableSeries, true);

        var grid = new Grid();
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });

        var gridSplitter = new GridSplitter
        {
            MinHeight = 4,
            HorizontalAlignment = HorizontalAlignment.Stretch,
            Background = new SolidColorBrush(Color.FromRgb(0xFF, 0xFF, 0x0))
        };

        Grid.SetRow(sciTickPriceChartSurface, 0);
        Grid.SetRow(gridSplitter, 1);
        Grid.SetRow(sciTickVolumeChartSurface, 2);

        grid.Children.Add(sciTickPriceChartSurface);
        grid.Children.Add(gridSplitter);
        grid.Children.Add(sciTickVolumeChartSurface);

        var priceChartSurfaceModifier = new ModifierGroup(

            // Allow pan on Left mouse drag
            new ZoomPanModifier { ExecuteOn = ExecuteOn.MouseLeftButton, ClipModeX = SciChart.Charting.ClipMode.None },
            // <!-- Allow Mousewheel Zoom -->
            new MouseWheelZoomModifier(),
            // <!-- Allow Zoom to Extents on double click -->
            new TickChartZoomExtentsModifier { ExecuteOn = ExecuteOn.MouseDoubleClick },
            // Alow cursor modifier
            new CursorModifier
            {
                SourceMode = SourceMode.AllSeries,
                ShowTooltipOn = ShowTooltipOptions.Always,
                ShowAxisLabels = true,
                ReceiveHandledEvents = true,
                ShowTooltip = true,
                IsEnabled = true,
            }
        );
        sciTickPriceChartSurface.ChartModifier = priceChartSurfaceModifier;

        var volumeChartSurfaceModifier = new ModifierGroup(

            // Allow pan on Left mouse drag
            new ZoomPanModifier { ExecuteOn = ExecuteOn.MouseLeftButton, ClipModeX = SciChart.Charting.ClipMode.None },
            // <!-- Allow Mousewheel Zoom -->
            new MouseWheelZoomModifier(),
            // <!-- Allow Zoom to Extents on double click -->
            new TickChartZoomExtentsModifier { ExecuteOn = ExecuteOn.MouseDoubleClick },
            // Alow cursor modifier
            new CursorModifier
            {
                SourceMode = SourceMode.AllSeries,
                ShowTooltipOn = ShowTooltipOptions.Always,
                ShowAxisLabels = true,
                ReceiveHandledEvents = true,
                ShowTooltip = true,
                IsEnabled = true,
            }
        );
        sciTickVolumeChartSurface.ChartModifier = volumeChartSurfaceModifier;

        var tickChartsMouseEventSharedGroupName = UUIDHelper.CreateUUIDString(false).ToString();
        MouseManager.SetMouseEventGroup(priceChartSurfaceModifier, tickChartsMouseEventSharedGroupName);
        MouseManager.SetMouseEventGroup(volumeChartSurfaceModifier, tickChartsMouseEventSharedGroupName);

        var tickChartSharedGroupName = UUIDHelper.CreateUUIDString(false).ToString();
        SciChartGroup.SetVerticalChartGroup(sciTickPriceChartSurface, tickChartSharedGroupName);
        SciChartGroup.SetVerticalChartGroup(sciTickVolumeChartSurface, tickChartSharedGroupName);

        this.ChartGrid.Children.Clear();
        this.ChartGrid.Children.Add(grid);
    }

    public void Dispose()
    {
        if (isDisposed == true) return;
        isDisposed = true;

        // Don't forget to clear chart grid child list.
        ChartGrid.Children.Clear();

        if (sciTickPriceChartSurface != null)
        {
            // Chart's Dispose method needs to be called when chart is 
            // no longer needed so that all unmanaged resources 
            // (DirectX etc.) are released.
            sciTickPriceChartSurface.ChartModifier?.OnDetached();
            sciTickPriceChartSurface?.Dispose();
            sciTickPriceChartSurface = null;

        }
        if (sciTickVolumeChartSurface != null)
        {
            // Chart's Dispose method needs to be called when chart is 
            // no longer needed so that all unmanaged resources 
            // (DirectX etc.) are released.
            sciTickVolumeChartSurface?.ChartModifier?.OnDetached();
            sciTickVolumeChartSurface?.Dispose();
            sciTickVolumeChartSurface = null;
        }
        GC.SuppressFinalize(this);
    }
Showing 4 results

Try SciChart Today

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

Start TrialCase Studies