Unfortunately no. You have two options.  1. Remove the reference from the VM
to that collection, that way no one will be referencing your collection and
the view, binding and collections will be released together.
2. Remove the binding (uiElement.DataContext=null) this will break the
subscriptions. The problem with this is that there's not a right point in
time where we can do it (e.g. closing or unloaded event).
3. Avoid using an ObservableCollection (or implementations of
INotifyCollectionChanged) so the binding doesn't create a subscription.

I'd suggest to scope the lifetime of the ViewModels to live as long as the
views and that way you can avoid having this issues, since you know that the
View will have subscriptions to the VM, but if no one else is referencing
your VM then both will die together. If someone is keeping your VMs alive,
then there's a problem.

Also some other times you have reference data that you will be using
throughout the life of the app, if that's the case, I'd suggest you when you
can to avoid using an ObservableCollection (you could configure this when
creating the proxy) and use a regular list. Sometimes you know that
the collection won't change or if you refresh it you will bring a totally
new collection instead of updating the original one, so it make sense to
have a regular list.

Check Delay's blog, he has a post that talks about this
http://blogs.msdn.com/delay/archive/2009/03/11/where-s-your-leak-at-using-windbg-sos-and-gcroot-to-diagnose-a-net-memory-leak.aspx

--------------------------------------------------------------------------------
Support procedure: https://www.codify.com/lists/support
List address: [email protected]
Subscribe: [email protected]
Unsubscribe: [email protected]
List FAQ: http://www.codify.com/lists/ozsilverlight
Other lists you might want to join: http://www.codify.com/lists

Reply via email to