- (void)foo
{
@try {
for (id o in os){
@autoreleasepool {
for (id o2 in moreOs){
// create a lot of autoreleased objects.
}
//exception raised
}
}
}
@catch (NSException *exception) {
// handle the exception
}
}
如果发生异常,编译器会重写上述代码以排空池还是会泄漏?
如果编译器确实重写了它,它将如何重写?
最佳答案
它不会耗尽水池。来自 Transitioning to ARC Release Notes :
On entry, an autorelease pool is pushed. On normal exit (break, return, goto, fall-through, and so on) the autorelease pool is popped. For compatibility with existing code, if exit is due to an exception, the autorelease pool is not popped.
关于objective-c - @autorelease 指令和异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8480624/