我花了很多时间来解决为什么当我的视图控制器从堆栈中弹出时没有被释放以获取内存。这是我正在使用的悬崖笔记版本:
- (IBAction)submitTurn:(UIButton *)sender {
...
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if (!error){
...
[game saveEventually];
...
[push sendPushInBackground];
}
}
else{
NSLog(@"Error submitting turn: %@ %@", error, [error userInfo]);
[[[UIAlertView alloc] initWithTitle:@"Error Saving Game" message:@"Try again later." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show];
}
} progressBlock:nil];
[self.navigationController popToRootViewControllerAnimated:YES];
}
当我运行我的应用程序并继续返回此视图控制器并提交轮到我时,仪器/泄漏显示我有此视图控制器的多个实时实例。但是,当我注释掉所有图像/游戏/推送保存并弹出视图时,内存就会被释放,并且我永远不会拥有多个实时实例。
我还尝试了这个以确保在 poppingToRoot 之前保存并完成所有内容。
- (IBAction)submitTurn:(UIButton *)sender {
...
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if (!error){
...
[game saveEventually:^(BOOL succeeded, NSError *error) {
...
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
[self.navigationController popToRootViewControllerAnimated:YES];
}];
}
}];
}
else{
...
}
} progressBlock:nil];
}
仍然,没有骰子。如何在不留下工件的情况下弹回根目录?