考虑这个例子:
- (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/