我發佈了另一個類似的問題。這是我的舊代碼,因爲有些ppl會說它會更好,但是我沒有找到釋放分配內存的解決方案。iphone UIImage數組內存泄漏(舊)
imageArray_danceright = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"FrankieDanceRetime_0001.jpg"],
.. 40 images
[UIImage imageNamed:@"FrankieDanceRetime_00040.jpg"],nil];
imageArray_danceleft = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"FrankieDanceRetime_0041.jpg"],
.. 40 images
[UIImage imageNamed:@"FrankieDanceRetime_00080.jpg"],nil];
imageArray_stand= [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"FrankieSingtRetime_0001.jpg"],
[UIImage imageNamed:@"FrankieSingtRetime_0002.jpg"],
[UIImage imageNamed:@"FrankieSingtRetime_0003.jpg"],nil];
//start animation
myimageview.animationImages = imageArray_stand;
myimageview.animationDuration = 0.23;
myimageview.contentMode = UIViewContentModeBottomLeft;
myimageview.animationRepeatCount = 0.0;
myimageview.image = [myimageview.animationImages objectAtIndex:1];
[myimageview startAnimating];
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touch = [[event allTouches] anyObject];
if ([touch view] == overlay_fuesserechts) {
[myimageview setAnimationImages:imageArray_danceright];
myimageview.animationDuration = 2.0;
myimageview.contentMode = UIViewContentModeBottomLeft;
myimageview.animationRepeatCount = 1;
[myimageview startAnimating];
}
if ([touch view] == overlay_fuesselinks) {
[myimageview setAnimationImages:imageArray_danceleft];
myimageview.animationDuration = 2.0;
myimageview.contentMode = UIViewContentModeBottomLeft;
myimageview.animationRepeatCount = 1;
[myimageview startAnimating];
}
它的工作正常..只是當我看着儀器/分配,它不釋放內存。 它開始於8MB的'立場'動畫,上升到32MB的fuesserechts,當我點擊fuesselinks它上升到55MB(我有6更多的動畫..所以更多,它只是崩潰) 當我確定[myimageview setAnimationImages:nil]; (在touchesBegan)每個setAnimationImages ...我仍然不釋放內存。 Allocatoins總體字節數仍然增加。 當我設置[myimageview.animationImages發佈];在(touchesbegan)每個setAnimationImages ...它甚至在幾次觸碰後崩潰。
感謝 克里斯
沒有代碼在哪裏釋放你的3個數組。你只創建一次或多次? – Vladimir 2010-08-10 13:40:32