xcode @autoreleasepool 没有 ARC?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7950583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
@autoreleasepool without ARC?
提问by fieldtensor
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 取代了自动释放池的手动使用,并且在幕后做了一些特殊的魔法来与 ARC 一起玩。
Yet, when I start a new project in Xcode 4.2 specifically with the ARC option turned offI still get @autoreleasepool statements in the template code.
然而,当我在 Xcode 4.2 中开始一个新项目时,特别是在关闭ARC 选项的情况下,我仍然在模板代码中得到 @autoreleasepool 语句。
What's the deal here?
这里有什么交易?
回答by
From http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool:
从http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool:
@autoreleasepool
may be used in non-ARC translation units, with equivalent semantics.
@autoreleasepool
可以在非 ARC 翻译单元中使用,具有等效的语义。
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.
@autoreleasepool { ... }
如果您的部署目标足够新,LLVM 3.0比 NSAutoreleasePool 快得多。不需要ARC。(...) 始终有效,但在 OS X 10.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 是什么,您都可以使用,而且它会比NSAutoreleasePool
在 OS X v10.7+ 和 iOS 5.0+ 上更快。