自动引用计数是否可以用作垃圾收集器? [英] Does Automatic Reference Counting work as garbage collector?

查看:61
本文介绍了自动引用计数是否可以用作垃圾收集器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS的最新版本中,Apple已实现了Objective-C的自动引用计数,但是我不认为这是可行的.

With last version of iOS Apple has implemented Automatic Reference Counting for Objective-C, but I don't understand as works.

推荐答案

自动引用计数会在编译时按照常规惯例将retainrelease消息插入您的代码中.因此,这就像您自己手动进行内存管理一样,只是编译器足够聪明,能够为您编写该位,而且出错的可能性很小.

Automatic reference counting inserts retain and release messages into your code for you at compile-time, following the normal conventions. So it's exactly as if you did the memory management yourself manually, except that the compiler is smart enough to be able to write that bit for you, and much less likely to make a mistake.

所以这不是垃圾回收,它更像是一种(非常简单的)静态分析形式.根据下面Catfish_Man提出的警告,您仍将获得压倒性的确定性内存管理,并且运行时成本的总体变化很小.

So it's not garbage collection, it's more like a (very simple) form of static analysis. And you still get overwhelmingly deterministic memory management and little overall change in runtime costs, as per the caveats raised by Catfish_Man below.

这篇关于自动引用计数是否可以用作垃圾收集器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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