When profiling an application, we can instantiate the control which binds to our class and then dispose that control.When opening a snapshot in dot Memory, the snapshot overview page will tell us about WPF binding leaks immediately.If I were rating the technical level of each post in this series, I would put this particular post somewhere in the range of moderate to advanced (but still very approachable :)).The Items Collection (a.k.a, the , that make up the logical content of the control. (I will use the terms “Items collection” and “Item Collection” interchangeably.) The “Type” of each item within the Items collection is Object.Before I start showing what’s wrong with MVVM in Silverlight and WPF and how to overcome it, I would like to define my position on subject: MVVM is a great pattern, WPF and Silverlight control’s library which is shipped with NET 4.0 is far from perfect for data binding development (especially Silverlight’s). To demonstrate this let’s try to develop some real life application using MVVM.After 2 minutes of thinking I decided to develop a plant classification application.
A similar issue to the WPF binding leak is the , for example, to our collection.
The only constraint when using this class is that instances of the collection must be created on the UI thread, so that events are raised on that thread.
In the previous example, the only thing to change to make the collection modifiable across threads is the instantiation of the collection in the View Model : to raise the event when the collection is modified from the main thread can cause unpredictable behavior.
Next, we can remove the binding by destroying the control and then taking a snapshot using dot Memory.
We would expect our collection to be removed from memory, yet if we look at the snapshot overview we can see a WPF collection binding leak had been detected.