Content Page Life Cycle

Conor.MurphyConor.Murphy ✭✭GBMember ✭✭

When setting the root page in the App.cs, Example: "MainPage = new ContentPage();" If i then do some navigation by setting the root page again to a new page : "MainPage = new NewContentPage();" Does the previous page stay open in the background? Do I have to manually close all references or does it get taken care of behind the scenes when setting a new root?

Thank you in advance !

Best Answer

  • NMackayNMackay mod GB mod
    Accepted Answer

    @Conor.Murphy

    You have to take care of memory management, behaviors, message registrations, event handlers etc need to be cleaned up in most cases for pages to allow pages to be released for garbage collection. Don't assume the Forms framework will do it all for you.

Answers

  • AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ ITMember ✭✭✭✭✭

    if you set MainPage, you are not doing "navigation". To add a "navigation" you should use

    MainPage = new NavigationPage(new ContentPage());
    

    to define the "root" of your NavigationStack, than PushAsync to "push" pages to your stack

  • Conor.MurphyConor.Murphy ✭✭ GBMember ✭✭

    @AlessandroCaliaro Sorry , i may have worded it wrong. I understand that i'm not using the navigation stack and setting the root via The MainPage property. For example this is going from a login screen to a main menu where the login screen does not need to exist in a navigation stack as it won't be revisited.

    But my question is more on does everything get cleaned up when setting a new root or does the programmer have to do some tidying?

  • NMackayNMackay mod GBInsider, University mod
    Accepted Answer

    @Conor.Murphy

    You have to take care of memory management, behaviors, message registrations, event handlers etc need to be cleaned up in most cases for pages to allow pages to be released for garbage collection. Don't assume the Forms framework will do it all for you.

  • Conor.MurphyConor.Murphy ✭✭ GBMember ✭✭

    @NMackay Thanks, That's cleared it up for me.

Sign In or Register to comment.