Xamarin Forms 在 UWP 上是否有内存泄漏?

Does Xamarin Forms have memory leak on UWP?

我写了 UWP,但这也可以在 Android 和 IOS 上,因为我只使用 VS2017 分析了 UWP 应用程序。

创建问题的步骤。 - 打开 VS 2017 并通过选择选项卡式页面或 masterdetail 页面启动一个新的 xamarin 表单项目。无需编写任何单个代码。

问题;

预期; 在第 3 个快照上看不到 ItemDetailsPage,因为我正在向后导航并且此页面从导航堆栈中弹出。所以它应该被删除,由 GC 收集或处理。

这是第三张快照的详细信息;

是我读错了这个快照还是 xamarin 表单应用程序有问题?

编辑:下面的截图还显示有 "cycle detected"。那是什么意思?我认为周期会导致内存泄漏,不是吗?

not see ItemDetailsPage on 3rd snapshot because I am navigating back and this page is popped from the navigation stack. so it should be removed, collected by GC or disposed.

如果您尝试导航到不同的详细页面然后返回并再次拍摄快照,您会发现 ItemDetailPage 的计数保持为 1。

有时,为了性能起见,页面或资源等对象将被适当地缓存和重用。如果你有一个包含大图片或资源的页面,你应该尝试手动处理它们以减少内存使用。

更新:

Now question is how to properly dispose it? where to do that? I keep reading OnDissapearing method which is not safe for me as it can be called on navigating forward , not only navigating back in the stack. what is your suggestion for that?

如果你不想销毁你的前进导航资源,你可以在前进导航时定义一个状态参数,不要销毁资源。例如:

bool forwardNavigating=false;
...
 protected override void OnDisappearing()
 {
    base.OnDisappearing();
    if (!forwardNavigating)
    {
        //dispose your resources
    }
 }

elow screenshot also stats that there is "cycle detected". what does that mean? i thought cycles cause memory leaks, dont they?

cycle detected 表示:

An object can reference a second object that directly or indirectly holds a reference to the first object.

请参考 Analyze .NET Framework memory issues 的循环引用。

个人认为:

我不认为这是 cycle detected 的内存问题。在某些情况下,当我们处于子对象中时,我们可能需要访问父对象。因此,我们需要一个 属性 Parent 而父级仍在引用子级。这种情况在视图中经常发生。不知道analyzer是怎么工作的,是不是我上面描述的情况。我想说的是 cycle detected 不等于内存泄漏。

在 Xamarin ListView 中动态更改 BindingContext(通过设置 null 重置 BindingContext 并重新分配新视图模型)时会发生相同的内存泄漏。有没有人遇到过这个问题