Does invoking Cleanup() on MvvmLight viewmodel unregisters all messages

Viewed 7468

I am using MvvmLight 4.0/C# in my first WPF4 project and still learning MVVM/WPF ropes where I find many of my former windows forms skills ineffective.

Anyway, I have viewmodels that derive from viewmodelbase that Register for messages and likewise have views do the same (Register for messages) for VM/VM and VM/V communication. All mvvmlight resources on cleanup say that I should Unregister messages to avoid memory leaks.

So when I am done using the views, I just call Messenger.Default.Unregister(this) in the unload event of the view/window. And when I am done using a viewmodel, I just invoke viewmodelbase.Cleanup() on my viewmodel reference assuming that the base implementation would do the (blanket) unregistering.

I want to know if just invoking Cleanup() on the viewmodel is enough or do I have to override this method in each of my viewmodels and explicityly call Unregister from within each override. For now I create/dispose most of my viewmodels on adhoc basis (not using SimpleIOC/ServiceLocator) and am only interested in unregistering all messages in the cleanup.

I found following SO tags connected but still leaves me unanswered on my query over implications of simply invoking ViewModelBase.Cleanup() vs Unregistering by explicitly overriding the method in the derived viewmodel.

Unregister(this) unregisters this instance from everything?

When and where to unregister messenger with mvvmlight

2 Answers
Related