Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Out of memory error with Navigation Page

Hi !

Do you have any update of when the "Out of memory" error will be fixed when using navigation pages on Android ?

Thank you ! Have a good day !

Answers

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    Are you referring to a confirmed bug in bugzilla or do you just get an out of memory error in your app?

  • EmmanuelGonzalezEmmanuelGonzalez FRMember

    Yes I think I'm referring to a confirmed bug in bugzilla :

    I get this error when navigating backward and forward a lot of times and it seems that pages are not destroyed / recycled properly in memory.

    Xamarin.Forms can almost not be used to produce real apps at the moment with this issue... sad :neutral:

    Thanks !

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    A possible workaround, when you navigate back and forth between pages, instead of creating a new one each time, have a list of constructed pages and push and pop them.

    e.g.
    instead of
    .PushAsync(new MyPage());

    do
    var page = dictionary[pageKey];
    .PushAsync(page);

    It would prevent old pages not being destroyed.

    Also if you have any event handlers or other things in your view that keeps it referenced to a view model or something similar then the page is unlikely to be destroyed even when you have navigated past it. It will stay in memory even though you can never get back to it. Building the page with OnAppearing, rather than in the constructor is how you get around refreshing the page when it is shown again.

  • EmmanuelGonzalezEmmanuelGonzalez FRMember

    Thank you for the workaround I will give it a try for sure ;-) !

    Anyway, I hope this critical issue will be resolved someday !

    Have a nice day !

  • Do you guys have any examples of this working? Our whole app is giving an OOM error and crashing, making the app unusable. The iOS version is working really well though. Could it also be some faulty assets perhaps?

Sign In or Register to comment.