Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:45:59+00:00 2026-06-18T06:45:59+00:00

I just need a little help to clarify how the Messenger class works with

  • 0

I just need a little help to clarify how the Messenger class works with ICleanup in MVVM-Light. I am creating a WPF 4 application in VB.Net with Mvvm-Light v4.

I have a messenger that registers for a message sent from a NavigationService Class I created as follows:

This is the registration in the ViewModel named ClientListViewModel

 ''register for messages
  Messenger.[Default].Register(Of INavigationService)(Me, "NavigationStart", False, AddressOf HandleParentChildNavigate)

This receives the NavigationService class and performs a check on it based on some other logic that is not relevant to this question.

The message is sent when a navigation event is triggered in my NavigationService class as follows

''Send message that navigation has been requested
Messenger.Default.Send(Of INavigationService)(Me, "NavigationStart")

This allows me to cancel the navigation event if my receiving class (in this case ClientListViewModel) has data validation errors, and it returns the focus to the record with errors. This all works great.

My question is, where and how do I unregister the message. I know that I need to in order to avoid memory leaks as I read on other posts. I have seen something like the following:

Public Overrides Sub CleanUp()
    Messenger.Default.Unregister(Me)
End Sub

This cleanup is in the same viewmodel (CientListViewModel) the receives the message.

So I have three questions:

  1. When should I call this cleanup method

  2. Is ther a way with the ViewModelLocator to unregister all message recipients when the application is closed down?

  3. This question is less relevant but I would appreciate some help too, How do I tell if I am getting “memory leaks” as a result of unregistered message recipients?

Thanks for your time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:46:00+00:00Added an answer on June 18, 2026 at 6:46 am

    When viewmodels should be “cleaned up” depends on your application and viewmodels usage. For example, I work on application with tabbed interface. When user closes tab application calls cleanup on viewmodel representing that tab (which itself goes through its viewmodels and calls cleanup on them as well). So the general rule – as soon as you don’t need viewmodel anymore – you should cleanup it (closing child window, tab, etc.) As for the other questions:

    2) It is indeed doesn’t matter on application closing if you cleanup your viewmodels. As on closing all memory will be freed up and you don’t get memory leaks 🙂

    3) You should check application memory usage. In our application we had serious problems (and actually still have but not that big) with memory leaks. We determined that we could have leaks by memory tracking: opened/closed many tabs, called GC.Collect() – but memory usage didn’t go down. We started to track memory leaks with WinDbg and found literally lots of places where we didn’t unregistered recipients from Messenger. Also, we’re using and old version of MVVM Light which is bound to CommandManager so we had problems with RelayCommands as well.

    Moral is – you should think about cleaning up resources during programming as later it can be painfull to find and fix it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just need a little help locating an error(?) in my code, is set the
guess its getting late, and Im a beginner, just need a little help.. Im
I am just getting started with Code Contracts, and need a little help in
I'm new to C# (asp.net) so i need little help. On this forum I
i just need a little help on how i could implement this function. i
I need a little help with my vb.net programming as I am trying to
I'm just figuring out my way around rails but I need a little help
Ok, I need a little help. I have these two PHP classes class menu
I just need little help, that is: many times i have seen http://www.xyz.com/index.jsp?etetet%rr^_frfwrw.... .
I just need a little help how to organize my code. This is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.