I use MvvmLight 4.0 / C # in my first WPF4 project and still study the MVVM / WPF ropes, where I find that many of my previous forms of window shapes are ineffective.
In any case, I have viewing models that are deduced from viewmodelbasethat Registerfor messages, and also have the same representations (case for messages) for exchanging VM / VM and VM / V data. All mvvmlight resources during cleanup say that I need Unregistermessages to avoid memory leaks.
So, when I finished using the views, I just call Messenger.Default.Unregister(this)the view / window unload event. And when I finished using viewmodel, I just call viewmodelbase.Cleanup()in my link viewmodel, assuming that the base implementation will make (populate) unregistered.
I want to know whether it is enough to just call Cleanup()on viewmodelor do I need to override this method in each of my view models and explicitly call Unregisterfrom within each override. At the moment I am creating / deleting most of my adhoc-based view models (without using SimpleIOC / ServiceLocator), and I'm only interested in unregistering all messages during the cleanup process.
I found that the following SO tags are related, but still go unanswered in my query about the capabilities of a simple call viewmodelbase.Cleanup()vs Unregistering, explicitly overriding the method in derivative viewmodel.
Unregister (this) will cancel this instance from everything?
When and where to unregister messenger using mvvmlight
source
share