开发者

Where is the leak here?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜