Does Automatic Reference Counting work as garbage collector? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-23 06:23:25

问题


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


回答1:


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.

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.




回答2:


Automatic Reference Counting implements automatic memory management for Objective-C objects and blocks, freeing the programmer from the need explicitly insert retains and releases. It does not provide a cycle collector; users must explicitly manage lifetime instead.

Read this spec - Automatic Reference Counting



来源:https://stackoverflow.com/questions/7756006/does-automatic-reference-counting-work-as-garbage-collector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!