2010-02-03 58 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