I have a Frame control in a Window xaml file. The frame navigates to user controls from a central search window. So when a user clicks on a search result, in the code behind, I call:
MyUserControl uc = new
When the user navigates back the search screen, I remove the last journal entry so that MyUserControl does not stay in memory. I do this in the event handler of the Navigated event of the NavigationService like so:
private void OnNavigated(object sender, NavigationEventArgs e)
if(e.Content is SearchView)
Unfortunately, the decontructor for MyUserControl never gets called. The Unload method gets called but it's never actually collected by the GC. I've ensured there are no lingering event handlers or any other references that would force it to stay in memory.
I verified this by bypassing the navigation service and just opening MyUserControl in a new window altogether. When the window is closed, the deconstructor is called and the memory is freed. But again, this is not the case with the Navigation Service.
View Complete Post