提前返回/退出时 @autoreleasepool {} 是否会耗尽?
考虑这个例子:
- (void)doSomething {
@autoreleasepool {
if (someCondition) {
/* ... allocate some autoreleased objects here ... */
return;
}
}
}
以前,使用手动 NSAutoreleasePools,如果我们提前返回,我们需要调用 [pool排出]
,否则池将不会被排出。 使用新的 @autoreleasepool {}
Consider this example:
- (void)doSomething {
@autoreleasepool {
if (someCondition) {
/* ... allocate some autoreleased objects here ... */
return;
}
}
}
Previously, with manual NSAutoreleasePools, if we returned early, we needed to call [pool drain]
, otherwise the pool would not be drained.
With the new @autoreleasepool {}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是肯定的:
来源:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool
The answer is YES:
Source:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool