现在的位置: 首页 > 综合 > 正文

iOS5 的新功能 ARC Automatic Reference Counting 如何关闭-ios入门

2018年02月20日 ⁄ 综合 ⁄ 共 858字 ⁄ 字号 评论关闭

在新发布的ios5中,有个很吸引眼球的特性就是“Automatic Reference Counting”,简单来说就是内存自动回收,看起来似乎是平时开发中遇到的各种内存问题的福音,仔细了解了一下,似乎没有那么美好:

1。 需要iOS5才支持
2。 很多引用的类库暂时还不支持.麻烦的是对大多数第三方库需要加禁用arc的编译flag,因为大多都因为兼容性还在使用手动内存管理。

而且当你开启了ARC后, 如果使用传统的手工 release 就是报错 'release' is unavailable: not available in automatic reference counting
modeAutomatic Reference Counting forbids explicit message send of 'release'



你可以按照如下方法关闭它  

Xcode 4.2: 点击项目后, 

Build Settings -> Apple LLVM compiler 3.0 - Language -> Objective-C Automatic Referencing Counting,
默认是YES 设置为NO即可。


但实际上
ARC确实比手动释放快,而且不会发生内存泄漏的情况,具体可以参考这里

http://clang.llvm.org/docs/AutomaticReferenceCounting.html
http://stackoverflow.com/questions/6385212/how-does-the-new-automatic-reference-counting-mechanism-work


一篇深入讨论 ARC的文章
http://longweekendmobile.com/2011/09/07/objc-automatic-reference-counting-in-xcode-explained/

本文转自http://www.cnblogs.com/mybkn/articles/2381224.html

本人初学ios, 欢迎指正,讨论QQ251995640

抱歉!评论已关闭.