This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi There, I have a chart (called "chart1") that has a DataSeries, We bind the DataSeries.ItemsSourceProperty to a ObservableCollection or BindingList (here after I will call it as MyDataCollection) Later on, I need to show different chart (called chart2) on the same page, so I tried to clear the databinding for chart1 by using BindingOperations.ClearBinding(theSeries, DataSeries.ItemsSourceProperty); When I check on memory, the chart1 is still in the memory and cannot be collected by Garbage Collection, because the CollectionChanged event on my MyDataCollection is still hanging there. (in my Data Model I did not use the event anywhere). I just want to keep one chart in memory when I switched between chart1 and chart2 (created a new chart for it every time I switch, my projects need me doing this, so please don't ask me about other methods). After switch for a while, I will have a lot of Chart objects hangs in the memory. If the MyDataCollection is a List, then the chart1 or 2 will be ready for garbage collection. But if I need to use the live data, then I have to use ObservableCollection or BindingList. Is that possible for adding a function in DataSeries to clean up the event handler? So it will not hanging on the memory? Thanks, Gordon |
|
|
If the problem caused is due to the WPF databinding, and a function in DataSeries to clean up the event handler is hard to do, we have a work around: 1) clear the data binding 2) recreate the binding list or observable collection, copy the data to the newly created list. This is ugly fixes but seems clear the memory holds. Gordon |
|
|
Hello Gordon Thanks for pointing this out. Adding a method to remove all event handlers should not be necessary as the Chart control is supposed to handle this internally without developers needing to worry about it. I was unable to reproduce this with an ObservableCollection, but the data series were not releasing events from BindingList. This has been fixed in the next nightly build. Additionally, If clearing the bindings does not work, try to set the ItemsSource of the old chart series to null - this will also trigger events to be removed. -Jason Fauchelle |
|
|
Hi Jason, I did set ItemsSource to null, but It will not make any difference. I am curious how did you fix it? Thanks, Gordon |
|
|
As mentioned, I only see this issue with BindingList - because we weren't removing the IBindingList event handlers, so the solution was to add that missing code in. Do you still see this problem with ObservableCollection? as this should be working fine. -Jason Fauchelle |
|
|
As of May 22, 2014 nightly build, I see the problem for both ObservableCollection and BindingList |
|
|
I downloaded May 30, Version 6 Nightly build, If I set Series.ItemsSource = null, it will solve the problem for binding list |
|
|
Is this still a problem with ObservableCollection? I have not yet been able to reproduce any memory leak. With the source code you'll be able to use a memory profiler to find exactly where the memory is being held up. Let me know how it goes. -Jason Fauchelle |
|
|
Hi Jason, Just to do the testing, I changed my code to use obsevablecollection. It is clean now, chart will not holds the memory after clear data binding for all series. Thanks, Gordon |
|