简体   繁体   中英

More Leaking Code help?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM