views:

96

answers:

2
-(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
+1  A: 

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.

Anon.
how do i do that?
Steve
Make `gameViewController` an ivar (instance variable) with properties and reference it as `self.gameViewController`.
Alex Reynolds
+2  A: 

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];
Joe Cannatti
thank you so much!
Steve
now it just highlights the last line as a leak[gameViewController release];
Steve