views:

64

answers:

2

Hi, 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]   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];
 }

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

A: 

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.

lukya
ok.. i removed the [myimageview.animationImages release]; but still it just crash when [myimageview setAnimationImages:imageArray_danceright];is fired ??
christian Muller
A: 

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?

Phil Nash
Before it worked just fine... the problem was it does not released the Memory and so after the 4th anim (i could see in Instruments/Allocation) it got 100MB and crashed. I would even post my old code again if you are willed to help :)
christian Muller
I would post the old code
Phil Nash
`[myimageview.animationImages release];` looks wrong to me too. I would make that `myimageview.animationImages = nil;`
Phil Nash
in fact that should be redundant at that point - setAnimationImages should release what it already was holding. Might be worth doing it in dealloc, tho. Does this object own myimageview, too? I don't see you releasing that
Phil Nash
Thanks... I posted my old Code here:http://stackoverflow.com/questions/3448911/iphone-uiimage-array-memory-leak-old For this question here... what do you mean with "does this object own myimageview,too" Which Object. Above is all i release.. you may let me know what else to release :) And as mentioned the old code is at the link above. thanks again. btw. should I am able to contact you directly..i would even send you the whole code... should i not find a solution i have to test with a timer and without Animation :(
christian Muller