泄漏在哪里?

时间:2010-02-03 22:40:34

标签: iphone objective-c xcode sdk

-(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

2 个答案:

答案 0 :(得分:2)

将gameViewController设置为.h

中的属性
@property(nonatomic,retain) GameViewController *gameViewController;

和.m

@synthesize gameViewController

然后在分配时使用该属性

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

并在最后发布

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

答案 1 :(得分:1)

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

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