Xamarin.Forms导航(内存管理)

huangapple go评论58阅读模式
英文:

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();

huangapple
  • 本文由 发表于 2020年1月3日 13:57:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59573832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定