UIViewController* vc = [[NSClassFromString(record.anObject) alloc] initWithNibName:record.anObject bundle:nil];
1) [myNavigationController navigateToViewController:vc animated:NO];
2) dispatch_async(dispatch_get_main_queue(), ^(void){
@autorelesepool
{
[myNavigationController navigateToViewController:vc animated:NO];
}
});
请检查代码 1 和 2。如果我使用 1,则 View Controller vc
在从导航堆栈弹出时被释放,如果我使用 2,则我的 View Controller 在从导航堆栈弹出时不会被释放导航堆栈。
我正在使用 ARC
。任何人都可以告诉我如何为第二次实现释放 vc 的内存?我尝试了 __block
类型的临时变量,并在 disaptch_async block 的末尾将其设置为 nil
但它不起作用。
最佳答案
您可以尝试以下方法:
__weak UIViewController *weakVC = vc;
dispatch_async(dispatch_get_main_queue(), ^(void){
[myNavigationController pushViewController:weakVC animated:NO];
}
关于iOS:如果我将 View Controller 实例传递给 dispatch_async block ,它不会被释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28297988/