cocoa - 提前返回/退出时 @autoreleasepool {} 是否会耗尽?

标签 cocoa automatic-ref-counting nsautoreleasepool llvm-3.0

考虑这个例子:

- (void)doSomething {
   @autoreleasepool {
      if (someCondition) {

         /* ... allocate some autoreleased objects here ... */

         return;
      }
   }
}

以前,使用手动 NSAutoreleasePools 时,如果我们提前返回,则需要调用[池耗尽],否则池将不会被耗尽。 使用新的 @autoreleasepool {}

最佳答案

答案是肯定的:

When the block is exited normally, whether by fallthrough or directed control flow (such as return or break), the autorelease pool is restored to the saved state, releasing all the objects in it. When the block is exited with an exception, the pool is not drained.

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

关于cocoa - 提前返回/退出时 @autoreleasepool {} 是否会耗尽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9209545/

相关文章:

iphone - 核心数据以编程方式访问 Z_PRIMARYKEY 的 Z_MAX 数据

ios - 所有对以编程方式创建的 subview 的引用都应该声明为弱吗?

ios - 迪尔德 : lazy symbol binding failed: Symbol not found: _objc_loadWeak

cocoa-touch - iOS 应用程序因 'message sent to deallocated instance' 而崩溃

objective-c - 应用程序退出事件

objective-c - AFNetworking 并发 Http 请求

iphone - IOS 调用 didFinishLaunchingWithOptions 的条件

xcode - 我如何知道哪个文件打开了 ARC,哪个文件关闭了 ARC?

ios - 使用@autoreleasepool 需要什么 iOS 版本?

ios - 如果在释放对象所属的池后释放对象,可能会发生什么?