gpt4 book ai didi

Xamarin 垃圾收集器和循环引用

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

在阅读 "Performance" 部分下的 Xamarin 文档时,我注意到以下章节:

The following diagram illustrates a problem that can occur with strong references:

Circular reference

Object A has a strong reference to object B, and object B has a strong reference to object A. Such objects are known as immortal objects due to the presence of the circular strong references. This parent-child relationship is not unusual, and as a result, neither object can be reclaimed by the garbage collector, even if the objects are no longer in use by the application.


那是我第一次听说 C#/.NET/Mono 上下文中的“不朽对象”。
然后页面继续建议使用 WeakReference在其中一个对象中,这将删除强循环引用并解决此“问题”。
同时,Xamarin 文档位于 garbage collection声称:

Xamarin.Android uses Mono's Simple Generational garbage collector. This is a mark-and-sweep garbage collector [...]


标记和清除 GC 是否不受循环引用的影响?

最佳答案

由于循环引用导致的内存泄漏仅适用于 Xamarin.iOS,对 native 对象使用引用计数。

关于仙器的页面还有says :

Boehm – This is a conservative, non-generational garbage collector. It is the default garbage collector used for Xamarin.iOS applications that use the Classic API.



第二个引述专门谈到 Xamarin.Android。

关于Xamarin 垃圾收集器和循环引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35491692/

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