iOS5 的新功能 ARC Automatic Reference Counting 如何關閉


在新發布的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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM