I am trying to model a multi line chart using chartingToolkit library in Wpf. The graph/chart has to run for atleast 8 -10 hrs. There is problem of linear process memory Increase (upto 800 MB or more). I need to plot real time data from serial Com Port (different slaves). I am calling 2 process UpadateValue and UpdateChart from DispatcherTimer.
While running this program, Process memory increases linearly with time (more than 900Mb observed from Task Manager..!!).
Please suggest me some things to resolve memory issue.
Thanks a Lot
What I have tried:
public partial class MainWindow : Window
{
ObservableCollection<KeyValuePair<int, int>> Collection0 = new ObservableCollection<KeyValuePair<int, int>>();
ObservableCollection<KeyValuePair<int, int>> Collection1 = new ObservableCollection<KeyValuePair<int, int>>();
/*..........continue.............*/
ObservableCollection<KeyValuePair<int, int>> Collection39 = new ObservableCollection<KeyValuePair<int, int>>();
Random rnd = new Random();
public int i = 0;
public MainWindow()
{
InitializeComponent();
Parallel.Invoke(() => { SetTimer1(); });
Parallel.Invoke(() => { SetTimer2(); });
}
private void SetTimer1()
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(ValueUpdate);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 2, 0);
dispatcherTimer.Start();
}
private void SetTimer2()
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(ChartUpdate);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 2, 0);
dispatcherTimer.Start();
}
private void ValueUpdate(object sender, EventArgs e)
{
int m = -40;
GC.Collect();
Collection0.Add(new KeyValuePair<int, int>(i, rnd.Next(m++, m++)));
Collection1.Add(new KeyValuePair<int, int>(i, rnd.Next(m++, m++)));
/*......continue......*/
Collection39.Add(new KeyValuePair<int, int>(i, rnd.Next(m++, m++)));
i = i + 1;
GC.Collect();
}
void ChartUpdate(object sender, EventArgs e)
{
GC.Collect();
LineChart0.DataContext = Collection0;
LineChart1.DataContext = Collection1;
/*.....continue.....*/
LineChart39.DataContext = Collection39;
GC.Collect();
}
}