0
votes

I have doubt regarding Xamarin.Forms MainPage property in terms of memory leak.

Say for instance I started my application with LoginPage

App.cs

MainPage = new LoginPage();

After successful login, LoginPage.cs

MainPage = new NavigationPage(new HomePage());

What happens with LoginPage instance? Is that remains in memory until garbage collector collects it, or it gets destructed?

1
the GC will handle it, unless you choose to explicitly dispose of it - Jason
Its problem then, because Pages may have images/large contents.. which is not good to have loaded in RAM. Don't we have option like finish current page and start new, same as Android!! - Afzal Ali
How is it a problem? The garbage collector will clean it up, and if you really want it to be cleaned up immediately, implement IDisposable on your page and do a simple check and clean it up properly. Alternatively you can force the garbage collector to run, but that's not a recommended practice. - Bill Reiss
I highly recommend brushing up on the Xamarin GC. developer.xamarin.com/guides/android/advanced_topics/…. - Joshua Poling

1 Answers

0
votes

I suggest uninstall the existing app in the emulator and redeploy the application again