导航到页面可提高内存使用率Windows Universal 8.1
我正在创建一个Windows Universal 8.1应用程序。每次我导航到一个页面,然后再导航回该页面,然后再导航到该页面,该页面的一个新实例就会保存在内存中。显然,垃圾收集器会在一段时间后释放内存,但是如果不需要,我宁愿不使用内存。有没有办法回收或处置这些页面?在Windows Uriveral App中,我们可以使用导航缓存模式来回收页面。它可以在页面的构造函数中设置。例如,我们希望回收一个主页:导航到页面可提高内存使用率Windows Universal 8.1,windows,navigation,windows-phone-8.1,win-universal-app,Windows,Navigation,Windows Phone 8.1,Win Universal App,我正在创建一个Windows Universal 8.1应用程序。每次我导航到一个页面,然后再导航回该页面,然后再导航到该页面,该页面的一个新实例就会保存在内存中。显然,垃圾收集器会在一段时间后释放内存,但是如果不需要,我宁愿不使用内存。有没有办法回收或处置这些页面?在Windows Uriveral App中,我们可以使用导航缓存模式来回收页面。它可以在页面的构造函数中设置。例如,我们希望回收一个主页: public MainPage() { this.InitializeCompon
public MainPage()
{
this.InitializeComponent();
// Set the NavigationCacheMode of Page to Enabled.
// The page is cached, but the cached instance is discarded when the size
// of the cache for the frame is exceeded.
this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
// OR Set the NavigationCacheMode of Page to Required.
// The page is cached and the cached instance is reused for every visit
// regardless of the cache size for the frame.
// this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;
}
设置后,我们可以返回主页,而无需重新创建
如果NavigationCacheMode设置为禁用。当从中导航时,页面的内存将被释放
有一个类似的问题是这样的:你可以使用NavigationCacheMode来做,请阅读我的答案。@wereworfBoy那么你不想回收但想处理的页面呢?是否在Windows.UI.Xaml.Navigation.NavigationCacheMode.Disabled的情况下执行此操作?或者它被保存在记忆中?如果你也能回答这个问题,我会接受你的回答;)