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