开发者

Where is the leak here?

开发者 https://www.devze.com 2022-12-19 06:31 出处:网络
-(IBAct开发者_StackOverflowion)startGameButtonClicked:(id)sender{ //gameViewController = NULL; //[gameViewController release];
-(IBAct开发者_StackOverflowion)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


set up gameViewController as a property in the .h

@property(nonatomic,retain) GameViewController *gameViewController;

and in the .m

@synthesize gameViewController

then use the property when assigning

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

and release at the end

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


Each time the button is clicked, you make a new gameViewController and push it into self.navigationController.

You want to not make a new one each time.

0

精彩评论

暂无评论...
验证码 换一张
取 消