Share via

Maui - memory raising when using Application.Current.MainPage.Navigation.PushAsync

Dani_S 5,581 Reputation points
2024-03-05T08:00:23.4966667+00:00

Hi,

I used only Application.Current.MainPage.Navigation.PushAsync(new page) only in my app for navigationg but the memory is raising.

I tested with published as exe (from Visual studio 17.8.4).

https://app.screencast.com/cFXT6QgHXsVja

The structure of the app is describe in:

https://learn.microsoft.com/en-us/answers/questions/1607099/maui-using-timer-in-multi-main-page-navigations

Implementing a ContentView to change different layout over time

Thanks in advance,

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author

  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
    2024-03-06T05:34:26.8033333+00:00

    Hello,

    For navigation, memory increases are expected behavior.

    When you call the Application.Current.MainPage.Navigation.PushAsync(new page) method, a new page object is created and saved to the navigation stack. This results in an increase in memory usage.

    These objects saved in the navigation stack will be released after being Popped, so generally speaking, this will not cause the user to occupy too much memory.

    If you need to not increase memory when changing pages, you can use the replace current page instead of the navigation method.

    Application.Current.MainPage = your page
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.