2010-02-03 55 views
1
-(IBAction)startGameButtonClicked:(id)sender{ 
    //gameViewController = NULL; 
    //[gameViewController release]; 
    //[gameViewController dealloc]; 

    if(!gameViewController){ 
     gameViewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil]; 
    } 


    appDelegate.ScoreID=0; 
    [gameViewController resetLevel]; 
    [gameViewController resetTheGame]; 
    [self.navigationController pushViewController:gameViewController animated:YES]; 
} <---Says the leak is here 
+0

稍后您会发布gameViewController吗? 并且resetLevel和resetTheGame方法是否干净? – 2010-02-03 23:15:15

回答

1

每次单击按钮时,都会创建一个新的gameViewController并将其推入self.navigationController。

你不想每次都做一个新的。

+0

我该怎么做? – Steve 2010-02-03 22:44:54

+0

使'gameViewController'成为具有属性的ivar(实例变量)并将其作为'self.gameViewController'引用。 – 2010-02-03 23:47:46

2

分配

self.gameViewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil]; 

,并在释放时设立gameViewController作为属性在.H

@property(nonatomic,retain) GameViewController *gameViewController; 

,并在.M

@synthesize gameViewController 

然后使用属性end

[self.navigationController pushViewController:gameViewController animated:YES]; 
[gameViewController release]; 
+0

非常感谢你! – Steve 2010-02-03 22:47:53

+0

现在它只是最后一行突出显示为泄漏 [gameViewController release]; – Steve 2010-02-03 22:54:19