问题描述
我是 Xcode 4.2 的新手,我还没有完全了解 ARC.然而,我确实读到 @autoreleasepool 取代了自动释放池的手动使用,并在幕后做了一些特殊的魔法来与 ARC 配合使用.
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.
然而,当我在 Xcode 4.2 中开始一个新项目时,特别是在关闭 ARC 选项的情况下关闭,我仍然在模板代码中得到 @autoreleasepool 语句.
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.
这里有什么交易?
推荐答案
来自 http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool:
@autoreleasepool
可以在非 ARC 翻译单元中使用,具有等效的语义.
and Greg Parker says [1] [2]:
LLVM 3.0 的 @autoreleasepool { ... }
如果您的部署目标足够新,则比 NSAutoreleasePool 快得多.不需要ARC.(...) 始终有效,但在 OS X 10.7 或 iOS 5.0 的部署目标上速度更快.
所以你可以使用 @autoreleasepool
而不管 ARC,它会比 NSAutoreleasePool
在 OS X v10.7+ 和 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+.
这篇关于@autoreleasepool 没有 ARC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!