eestein
eestein

Reputation: 5114

How to remove previous pages from memory?

I'm using an implementation of Master/Detail in my Forms app. The problem is that even after I change pages the previous one is still running, I even had to do some inactive/isActive code in order to stop the code execution of those pages.

This is how I change pages:

        public void GoTo(Page page)
        {
            Detail = new NavigationPage(page);
            IsPresented = false;
            UserDialogs.Instance.HideLoading();
        }

Then I do:

Application.Current.HomePage.GoTo(new ServiceSelectionPage());

But the previous page is kept running. What am I doing wrong? Or how do I remove those pages from memory? I tried setting Detail = null to no avail.

Thanks!

Upvotes: 2

Views: 1137

Answers (1)

Daniel Luberda
Daniel Luberda

Reputation: 7454

It is by design. You could:

  • Set their instances to null, then wait for garbage collection. You could force it with GC.Collect(); - but it's not guaranteed.
  • Reuse pages instances (use same Page instance and only change current BindingContext). You could use custom Page Factory for that.

Upvotes: 1

Related Questions