内存管理如何在Xamarin.IOS上运行 [英] How does memory management works on Xamarin.IOS

查看:107
本文介绍了内存管理如何在Xamarin.IOS上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解在使用xamarin.ios并在实际iOS设备上运行应用程序时内存管理的工作原理。我的理解是iOS平台没有垃圾收集器,但该平台使用ARC(Automatci Reference Counting)。

I am trying understand how memory management works when using xamarin.ios and running the app on an actual iOS device. My understanding that the iOS platform does not have a garbage collector, but the platform uses ARC (Automatci Reference Counting).

编译后的应用程序是否会使用ARC而不是垃圾回收?

Is it true that the compiled app will be using ARC instead of garbage collection?

推荐答案

ARC是一种适用于Objective-C编译器编译的源代码的技术,它具有转换每项任务的效果像这样:

ARC is a technology that applies to source code compiled by the Objective-C compiler and it has the effect of turning every assignment like this:

foo = bar

其中foo和bar是NSObjects的代码如下:

Where "foo" and "bar" are NSObjects into the following code:

if (foo != null)
   [foo release];
if (bar != null)
   [bar retain]
foo = bar;

正如你所看到的,它只是一个编译器技巧,它会重写你的代码,所以你不要忘记保留/发布内容并仅适用于Objective-C。

As you can see, it is just a compiler trick that rewrites your code so you do not forget to retain/release things and only applies to Objective-C.

对于MonoTouch,Objective-C库使用哪些(ARC或不使用ARC)并不重要使用现有的文档协议来保留何时以及何时释放。 MonoTouch遵循这些规则。

What Objective-C libraries use (ARC or no ARC) is not really important to MonoTouch, as far as they use the existing documented protocol for when to retain and when to release. MonoTouch just follows those rules.

C#对象没有保留/释放代码路径,而只是使用GC来确定哪些对象存活。

C# objects do not have the retain/release code path, and instead just use GC to determine which objects are alive.

当Objective-C对象浮出水面时,Monotouch会引用一个引用(它会调用retain)。当MonoTouch GC确定任何托管代码无法再访问某个​​对象时,GC会调用该对象的释放。

When Objective-C objects are surfaced to the C# world, Monotouch takes a reference (it calls retain). When the MonoTouch GC determines that an object is no longer reachable by any managed code, then the GC calls release on the object.

这篇关于内存管理如何在Xamarin.IOS上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆