Silverlight Toolkit – Chart Control Memory Leak Problem

24 Jan


Two weeks ago we had a memory leak problem with Silverlight Toolkit Chart Control. If you want to see a sample code for reproducing and more details you can read details of the issue on CodePlex. After spending some time with this Silverlight Toolkit Chart Control Memory Leak problem, I figured out the reason of memory leak.

Chart control has a weak reference implementation but if you add or remove members after first initialization of ItemSource of LineSeries object it doesn’t invoke the weak reference detaching logic. I don’t remember all base class and method names in SilverLight Toolkit but after spending one day with WinDBG, Silverlight Spy and source code of Silverlight Toolkit I found the problem.

Solution is very easy: instead of adding and removing members to existing ObservableCollection. Create a new instance of ObservableCollection and set ItemSource everytime you need to update datasource.

Comment Form