Xamarin 垃圾收集器和循环引用
Xamarin garbage collector and circular references
在阅读 "Performance" 部分下的 Xamarin 文档时,我注意到以下章节:
The following diagram illustrates a problem that can occur with strong references:
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
,这将删除强循环引用并解决此“问题”。
同时,garbage collection 上的 Xamarin 文档声称:
Xamarin.Android uses Mono's Simple Generational garbage collector. This is a mark-and-sweep garbage collector [...]
标记和清除 GC 是否不受循环引用的影响?
由于循环引用导致的内存泄漏仅适用于 Xamarin.iOS,对本机对象使用引用计数。
关于不朽物品的页面还有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.
在阅读 "Performance" 部分下的 Xamarin 文档时,我注意到以下章节:
The following diagram illustrates a problem that can occur with strong references:
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
,这将删除强循环引用并解决此“问题”。
同时,garbage collection 上的 Xamarin 文档声称:
Xamarin.Android uses Mono's Simple Generational garbage collector. This is a mark-and-sweep garbage collector [...]
标记和清除 GC 是否不受循环引用的影响?
由于循环引用导致的内存泄漏仅适用于 Xamarin.iOS,对本机对象使用引用计数。
关于不朽物品的页面还有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.