简体   繁体   English

更多泄漏代码帮助吗?

[英]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. 我将customYourGameViewController设置为属性并对其进行了合成。

It looks like customizeYourGameViewController is a property on your class. 看起来customizeYourGameViewController是类的一个属性。 Is it set to retain? 它会保留吗? If so, the @synthesized setter for customizeYourGameViewController is doing a retain and you'll need to release somewhere. 如果是这样,customizeYourGameViewController的@synthesized设置器将进行保留,您需要在某个地方释放。

Although, thinking about this, I'm wondering: Why is customizeYourGameViewController a property? 尽管,考虑到这一点,我想知道:为什么customizeYourGameViewController是一个属性? 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. 然后删除ivar并删除属性。

You are allocating CustomizeYourGameViewController but not releasing it. 您正在分配CustomizeYourGameViewController但没有释放它。 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. 我不知道它在做什么(你有一个名为伊娃customizeYourGameViewController ),但它可能不是做什么,你认为它在做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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