views:

52

answers:

2
-(IBAction)customizeYourGameButtonClicked:(id)sender {
 [self playHumanHitSound];

 self.customizeYourGameViewController = [[CustomizeYourGameViewController alloc]
    initWithNibName:@"CustomizeYourGameViewController" bundle:nil];

 [self.navigationController
     pushViewController:customizeYourGameViewController animated:YES];
 [customizeYourGameViewController release];
}

Can't understand why this is leaking. I set customizeYourGameViewController as a property and synthesized it.

A: 

You are allocating CustomizeYourGameViewController but not releasing it. Makes the changes below.

[[[CustomizeYourGameViewController alloc] nitWithNibName:@"CustomizeYourGameViewController" bundle:nil] autorelease];

and you can get rid of the final

[customizeYourGameViewController release];

I'm not sure what it's doing (do you have a iVar named customizeYourGameViewController), but it's probably not doing what you think it's doing.

kubi
The last line of the sample is [customizeYourGameViewController release];. Adding an autorelease might very work around the leak, but it's not going to correct the logic.
Steven Fisher
thanks. Didn't notice that in the unformatted code.
kubi
Ah, I didn't realize he'd formatted it AFTER posting. Sorry to jump on you!
Steven Fisher
+3  A: 

It looks like customizeYourGameViewController is a property on your class. Is it set to retain? If so, the @synthesized setter for customizeYourGameViewController is doing a retain and you'll need to release somewhere.

Although, thinking about this, I'm wondering: Why is customizeYourGameViewController a property? Unless you're communicating with the controller elsewhere, it should just be a local variable.

-(IBAction)customizeYourGameButtonClicked:(id)sender {
 [self playHumanHitSound];

 id customizeYourGameViewController = [[CustomizeYourGameViewController alloc]
    initWithNibName:@"CustomizeYourGameViewController" bundle:nil];

 [self.navigationController
     pushViewController:customizeYourGameViewController animated:YES];
 [customizeYourGameViewController release];
}

Then remove the ivar and remove the property.

Steven Fisher