SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

Answered
0
0

Recently a customer asked us on a support ticket:

We are trying to free the memory used by SciChart but it seems like
there is a large amount of memory still held somewhere in the code.
Attached

Bug scenario:

  1. Run the 50-Channel EEG Example
  2. Start the UI, With task manager memory usage is around 40 MB.
  3. Press Run, memory usage increase to ~130 MB.
  4. Press Stop, memory usage remains the same (around 130 MB).
  5. Call the garbage collector manually, on the second call of the garbage collector the memory stays above 100 MB.

How can we release the memory allocated by a DataSeries in SciChart WPF?

Version
6.6.0
  • You must to post comments
Best Answer
0
0

The reason for this is SciChart WPF’s XyDataSeries is designed to cache memory that has been previously allocated. For example, if you call this code:

var xValues = new double[10_000_000]; // Allocate 10M points X,Y = 160MBytes
var yValues = new double[10_000_000]; 
var dataSeries = new XyDataSeries<double, double>();
dataSeries.Append(xValues, yValues); 
// Clear data 
dataSeries.Clear();

The memory allocated will not be released.

This is by design.

There are many use-cases where you may want to call dataSeries.Append() dataSeries.Clear() dataSeries.Append() with a new dataset of the same size. By caching memory we can ensure the highest possible performance of your application.

How to release the memory allocated in a DataSeries?

In SciChart WPF v6.5 and below, if you set all references to a DataSeries equal to null, the garbage collector will reclaim the memory.

In SciChart WPF v6.6 and above, we have added a new optional flag to force the release of memory. Call this instead to ensure memory is deleted:

var xValues = new double[10_000_000]; // Allocate 10M points X,Y = 160MBytes
var yValues = new double[10_000_000]; 
var dataSeries = new XyDataSeries<double, double>();
dataSeries.Append(xValues, yValues); 
// Clear data 
bool forceDelete = true;
dataSeries.Clear(forceDelete);

Note this will mean the next time you call DataSeries.Append() SciChart will have to re-allocate memory which can be an expensive operation.

For more details please take a look at the ‘Control Over Allocated Memory’ section of the SciChart WPF v6.6 Release notes.

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.