我測試我的應用程序的工具, ,我看到我的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