SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Have a good day.
I’m working with scichartsurface, where I’m drawing a lot of lines with the help of IRenderContext2D. I’ve found out that this way of drawing took too much memory. For example when I displayed only surface, it took only ~80 Mb (Image 1), but when I displayed the graph using checkbox, began to scroll and pan my graph, the usage of memory increased to ~160 Mb (Image 2).
What is the reason of such behaviour?
Thanks in advance
I’ve attached the project: https://yadi.sk/d/cYP6RFVXhfjRS
Hi Egor,
I investigated your sample attached, and while I do see an increase in memory usage when panning, this memory is quickly reclaimed by the garbage collector, so I do not believe there is a memory leak.
A memory leak is a “gradual loss of available computer memory when a program (an application or part of the operating system) repeatedly fails to return memory that it has obtained for temporary use.”
As you can see below, SciChart is returning the memory as soon as the garbage collector runs (which is decided by .NET, not by us).
Below: Memory is reclaimed when the Garbage Collector runs
I have modified your sample to perform a garbage collection to test if memory is released. You can verify this by adding this code to your application:
XAML
<StackPanel Orientation="Horizontal">
<CheckBox Margin="5" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding IsCheckedDisplay}" Content="Display Graph"/>
<Button Margin="5" Content="Garbage Collect?" Click="ButtonBase_OnClick"></Button>
</StackPanel>
CSharp
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
Let me know if you see the same.
What causes memory growth in your application?
As for what causes this memory usage to grow so quickly, if we comment out this code in yoru application, then the memory stays stable
private void OnRedrawWellSection(object sender, IRenderContext2D e)
{
// ...
}
So I suggest investigating this area for memory problems. One line of code which looks suspect is this:
WriteableBitmap writeableBmp = BitmapFactory.New(width, height);
Creating a new bitmap every single redraw will cause unmanaged memory to grow rapidly. I would suggest caching this bitmap and only recreating if the size changes.
Best regards,
Andrew
Hello again!
I’ve modified my project to run faster. I’ve put BackgroundImageAnnotation, from which we create sprite, outside the function. But when I run the application, the image freezes and doesn’t redraw.
What is the reason? And how can I fix it?
I’ve attached modified project below.
Please login first to submit.