且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS5 的新功能 ARC Automatic Reference Counting 如何关闭

更新时间:2022-09-08 14:05:50

在新发布的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即可。
iOS5 的新功能 ARC Automatic Reference Counting 如何关闭
但实际上 ARC确实比手动释放快,而且不会发生内存泄漏的情况,具体可以参考这里
http://clang.llvm.org/docs/AutomaticReferenceCounting.html
http://***.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/

   本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/articles/2381224.html,如需转载请自行联系原作者