我测试我的应用程序的工具, ,我看到我的UIImage和UIImageView的是内存泄漏想疯了......的UIImage和UIImageView的内存泄露
我基本上使用递归,所以相同的变量得到在每次通话中加载不同的图像。
nextImageName = [[NSString alloc] init];
nextImageName2 = [[NSString alloc] init];
nextImageName = [[currentPlayers objectAtIndex:playerIndex] retain];
nextImageName2 = [[currentPlayers objectAtIndex:(playerIndex+1)] retain];
nextImage = [[UIImage alloc] init];
nextImage2 = [[UIImage alloc] init];
nextImage = [UIImage imageNamed:nextImageName];
nextImage2 = [UIImage imageNamed:nextImageName2];
nextImageView = [[UIImageView alloc] init];
nextImageView2 = [[UIImageView alloc] init];
nextImageView = [[UIImageView alloc] initWithImage:nextImage];
nextImageView2 = [[UIImageView alloc] initWithImage:nextImage2];
NSLog(@"r:%d",currentRound);
NSLog(@"%d vs. %d", playerIndex, playerIndex+1);
buttonOne = [[UIButton alloc] init];
buttonTwo = [[UIButton alloc] init];
playerOne = nextImageView;
playerTwo = nextImageView2;
playerOne.frame = CGRectMake(180.0, 200.0, 275.0, 275.0);
playerTwo.frame = CGRectMake(550.0, 200, 275.0, 275.0);
buttonOne.frame = CGRectMake(180.0, 200.0, 275.0, 275.0);
buttonTwo.frame = CGRectMake(550.0, 200.0, 275.0, 275.0);
[buttonOne addTarget:self action:@selector(announceWinner:)
forControlEvents:UIControlEventTouchUpInside];
[buttonTwo addTarget:self action:@selector(announceWinner2:)
forControlEvents:UIControlEventTouchUpInside];
任何人都可以帮我吗?这是让我坚果..
我原来已释放所有dealloc变量,但它似乎没有进入dealloc,所以我也把它放在viewDidUnload和didReceiveMemoryWarning。
你说得对!我分配了很多次,只发布一次...... Thanx! – CosmicRabbitMediaInc 2011-03-26 08:05:05
您可能还想在下面加入Bastian的答案。他也提出了一个有效的观点。 – aroth 2011-03-26 08:08:21