开发者

iphone UIImage array memory leak

I had that question before, tried as answered, but still it does not work.

Before I allocated with:

imageArray_danceright =  [[NSArray alloc] initWithObjects:

I came adviced to do like bellow, but now it crash immediatly after second anim is called:


//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]   pathForReso开发者_开发问答urce:@"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];
 }

Its starts with the "stand" animation.. but when i fire touchesbegan it crashes immediatly at:

    [myimageview setAnimationImages:imageArray_danceright];

and i have no idea. I tried so many things. Now I hope you have an idea.

thx chris


Because you are autoreleasing your image arrays, by the time it gets to TouchesBegan they have already been released. Who told you to use arrayWithObjects instead of alloc - initWithObjects ? It sounds like your earlier version would have been more correct. What was the problem you were having with that?


You surely don't need the [myimageview.animationImages release]; at the beginning of touches began. You are creating autoreleased array objects and assigening them to the imageview which releases them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜