2010-08-10 55 views
0

我之前有過這個問題,試着回答,但仍然無法正常工作。iphone UIImage陣列內存泄漏

之前我分配了:

imageArray_danceright = [[NSArray alloc] initWithObjects: 

我就勸做這樣波紋管,但現在它立刻崩潰第二阿尼姆被調用後:


//init areas: 

imageArray_stand = [NSArray arrayWithObjects: 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankieSingtRetime_0001" ofType:@"jpg"]], 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankieSingtRetime_0002" ofType:@"jpg"]], 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankiePeaceRetime_0003" ofType:@"jpg"]],nil]; 


imageArray_danceleft = [NSArray arrayWithObjects: 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankiePeaceRetime_0001" ofType:@"jpg"]], 
.. 40 images 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankiePeaceRetime_0040" ofType:@"jpg"]],nil]; 

imageArray_danceright = [NSArray arrayWithObjects: 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankiePeaceRetime_0041" ofType:@"jpg"]], 
.. 40 images 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FrankiePeaceRetime_0080" ofType:@"jpg"]],nil]; 


//start: 
[myimageview setAnimationImages:imageArray_stand]; 


myimageview.animationDuration = 0.23; 
myimageview.contentMode = UIViewContentModeBottomLeft; 
myimageview.animationRepeatCount = 0.0; 
myimageview.image = [myimageview.animationImages objectAtIndex:1]; 
[myimageview startAnimating]; 


// ------ in my 'touchesBegan" i have: 

if ([touch view] == overlay_fuesserechts) { 
    [myimageview.animationImages release]; 
    [myimageview setAnimationImages:imageArray_danceright]; 

    myimageview.animationDuration = 2.0; 
    myimageview.contentMode = UIViewContentModeBottomLeft; 
    myimageview.animationRepeatCount = 0; 
    [myimageview startAnimating]; 
} 


- (void)dealloc { 
[imageArray_stand release]; 
imageArray_stand=nil; 
[imageArray_danceright release]; 
imageArray_danceright=nil; 
[imageArray_danceleft release]; 
imageArray_danceleft=nil;  
    super dealloc]; 
} 

它開始與「站」動畫..但是當我着火touchesbegan立即崩潰在:

[myimageview setAnimationImages:imageArray_danceright]; 

我不知道。我嘗試了很多東西。現在我希望你有一個想法。

THX 克里斯

+0

任何log @ console? – 2010-08-10 11:47:21

+0

沒有..多數民衆贊成在概率..它只是停止。我在[myimageview setAnimationImages:imageArray_danceright]之前和之後做了一個NSLog;爲此,我知道它崩潰了:) – 2010-08-10 12:00:30

回答

0

因爲你正在自動釋放你的圖像數組,所以當它到達TouchesBegan時,它們已經被釋放。 誰叫你用arrayWithObjects代替alloc - initWithObjects? 這聽起來像你的早期版本會更加正確。那是什麼問題?

+0

之前它工作得很好......問題是它沒有釋放內存,所以在第四動畫(我可以在樂器/分配中看到)之後,它得到了100MB並崩潰。如果你願意幫助,我甚至會再次發佈我的舊代碼:) – 2010-08-10 11:57:12

+0

我會發布舊代碼 – philsquared 2010-08-10 12:05:30

+0

'[myimageview.animationImages release];'看起來也是我的錯。我會讓這個'myimageview.animationImages = nil;' – philsquared 2010-08-10 12:06:17

0

你肯定不需要[myimageview.animationImages release];在接觸之初就開始了。你正在創建autoreleased數組對象,並將它們分配給釋放它們的imageview。

+0

好吧..我刪除了[myimageview.animationImages發佈];但仍然只是當[myimageview setAnimationImages:imageArray_danceright]; 被解僱? – 2010-08-10 11:51:35