英文:
Xamarin.Forms Navigation (Memory Management)
问题
假设我有5个需要依次打开的页面,而且实际上我不想返回。我可以在OnAppearing和OnDisAppearing上订阅和取消订阅事件以避免内存泄漏。但是所有这些页面都会在导航堆栈中,这会消耗内存。那么如何从内存中删除这些页面,或者如何高效地导航?
英文:
Suppose I have 5 pages that I need to open one after another, and I don't want to go back actually. I can subscribe and unsubscribe the event on OnAppearing and OnDisAppearing to avoid memory leaks. But all the pages will be in the Navigation stack and it will consume memory. So how to remove those pages from memory, or how to efficiently navigate?
答案1
得分: 1
我明白你的意思,如果不需要返回到导航堆栈,聪明的做法就是不创建导航堆栈,而是将 MainPage 属性更改为要使用的新页面,类似以下方式:
Application.Current.MainPage = new NewMainPage();
英文:
As I understood you never have to go back in the Navigation Stack if that is the case the smart way would be to never create one and just change the MainPage property to the new page that you want to use something like below:
Application.Current.MainPage= new NewMainPage();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论