Does cleanup call () in view mode MvvmLight cancels all messages

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

+4
source share
2 answers

Just look at the code, it will open the source code anyway.

    /// <summary>
    /// Unregisters this instance from the Messenger class.
    /// <para>To cleanup additional resources, override this method, clean
    /// up and then call base.Cleanup().</para>
    /// </summary>
    public virtual void Cleanup()
    {
        MessengerInstance.Unregister(this);
    }

So the method Cleanupreally makes it pretty clear. And if you want other cleanups:

To clear additional resources, override this method, clear, and then call base.Cleanup ()

+5
source

, . Messenger.Default.Unregister(this). , .

. ken2k. , , . , . , , .

LB:

ICleanup - (, , ..)

from SO

0

All Articles