嗨,我使用块来实现将ViewController推送到堆栈上。我的代码如下:

我的问题是,对于内存管理,我可以在哪里释放firstView实例?我试图在完成块本身中释放它,但是如果我从splashView按下返回按钮到firstView,我将收到一个“内存问题”

FirstViewController *firstView = [[FirstViewController alloc]init];

[firstView setCompletionHandler:^(BOOL isRequestInvite){

    splashView=[[AuthSplashController alloc] init];
    [splashView setCompletionHandler:onceCompleted];

    [navCon pushViewController:splashView animated:YES];
    //[firstView release];

}];

[navCon pushViewController:firstView animated:NO];

因此,在这种情况下,发布firstView的最佳位置在哪里?

最佳答案

我认为将其推入导航堆栈后即可release firstView,因为保留计数将增加:

 [navCon pushViewController:firstView animated:NO];
 [firstView release];

或者,您可以将该对象标记为autoreleased:
 FirstViewController *firstView = [[[FirstViewController alloc]init] autorelease];

10-08 01:05
查看更多