gpt4 book ai didi

xamarin.forms - 在 Xamarin 中,使用 Navigation.RemovePage() 时如何避免内存泄漏

转载 作者:行者123 更新时间:2023-12-04 15:22:14 25 4
gpt4 key购买 nike

在我的 Xamarin 应用程序中,我有五个页面,第 1 页、第 2 页、第 3 页、第 4 页和第 5 页。从第 5 页导航到第 3 页时,我调用了 Navigation.RemovePage() 以删除 NavigationStack 中的第 4 页。但是,在调用 RemovePage() 时存在巨大的内存泄漏。我想知道在尝试删除 NavigationStack 中两个页面之间的页面时是否有任何解决方法可以避免内存泄漏? (因为第 3 页不是根页,所以我不能使用 PopToRootAsync())
此外,任何人都可以向我解释为什么使用 PushModalAsync() 会删除 NavigationStack 中的所有页面,并且只保留当前添加的页面以及 NavigationStack 和 ModalStack。
非常感谢。

最佳答案

In Xamarin, how to avoid memory leak when using Navigation.RemovePage()


在测试过程中,当 RemovePage时不会泄漏内存。方法被调用。
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.RemovePage( Navigation.NavigationStack.Where(a=> a is Page4).FirstOrDefault());
}

anyone can explains me why using PushModalAsync() will remove all pages in NavigationStack and only leaves the current added page and in both NavigationStack and ModalStack.


匹配的 PushModalAsync UWP 平台中的导航行为显示 ContentDialog .并且不会影响 NavigationStack以下是测试代码。
private void PushClick(object sender, EventArgs e)
{
Navigation.PushModalAsync(new MainPage());
foreach (var item in Navigation.NavigationStack)
{
System.Diagnostics.Debug.WriteLine(item.GetType().Name);
}
}
有关完整的代码示例,请参阅此 link .

关于xamarin.forms - 在 Xamarin 中,使用 Navigation.RemovePage() 时如何避免内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63059758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com