@autoreleasepool without ARC?

你离开我真会死。 提交于 2019-11-26 07:35:22

问题


I\'m new to Xcode 4.2, and I\'m not yet fully up to speed on ARC. However, I did read that @autoreleasepool replaces the manual use of autorelease pools and does some special magic under the hood to play nice with ARC.

Yet, when I start a new project in Xcode 4.2 specifically with the ARC option turned off I still get @autoreleasepool statements in the template code.

What\'s the deal here?


回答1:


From http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool:

@autoreleasepool may be used in non-ARC translation units, with equivalent semantics.

and Greg Parker says [1] [2]:

LLVM 3.0's @autoreleasepool { ... } is much faster than NSAutoreleasePool if your deployment target is new enough. No ARC required. (…) always works, but it's faster with deployment target of OS X 10.7 or iOS 5.0.

So you may use @autoreleasepool regardless of ARC, and it’ll be faster than NSAutoreleasePool on OS X v10.7+ and iOS 5.0+.



来源:https://stackoverflow.com/questions/7950583/autoreleasepool-without-arc

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