Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Proper way to Dispose ViewModel #22

Open
soooraj opened this issue Feb 22, 2019 · 2 comments
Open

Proper way to Dispose ViewModel #22

soooraj opened this issue Feb 22, 2019 · 2 comments

Comments

@soooraj
Copy link

soooraj commented Feb 22, 2019

@markjulmar : Could you please help me on below issue.

In my app I am using DependencyServiceExtension in the library to create my ViewModel. For example

BindingContext="{infrastructure:DependencyService Type={x:Type viewModels:HomeViewModel},
                                                      Scope=NewInstance}">

Due to some reason I don't want to keep the same instance of my view model through out the life time of the app. That is the reason I am using Scope as new Instance.

But now I noticed that the View Model that are created while navigation are not disposing at all. The events that I registered are firing for multiple times, based on the number of times I navigated to the page.

This is creating lot of issues in my application. Could you please let me know the best method to dispose this view models when the user navigates back (INavigationService.GoBack) method.

@soooraj
Copy link
Author

soooraj commented Mar 15, 2019

@markjulmar : Ping

@DennisWelu
Copy link

I've found this to be a problem a times generally speaking where the View having a BindingContext of the ViewModel causes the View/ViewModel combo to leak. When the view is "done" try setting the BindingContext to null. This seems to break anything tied through bindings and allow the cleanup.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants