gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:02:14 25 4
gpt4 key购买 nike

考虑这个例子:

- (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com