I posted another question similar. This is my old code as some ppl say it would be even better, but there i didnt found a solution to release the allocated memory.
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];
}
Its works fine.. just when i look in Instrument/Allocation, it does not release the memory.
It starts with 8mb for the ‘stand’ anim, goes up to 32mb for fuesserechts and when i click fuesselinks it goes up to 55mb (i have 6 more anim.. so a few more and it just crash)
When I do set [myimageview setAnimationImages:nil]; (in touchesBegan) for each setAnimationImages … i still does not release the Memory. All Allocatoins Overall bytes, still increase.
When I do set [myimageview.animationImages release]; in (touchesbegan) for each setAnimationImages… it even crash after a few touches.
Thanks
Chris
Ok, now I see your original code I think I see where the advice came from. Instead of
imageNamed:you might want to useimageWithContentsOfFile:(as you did in your earlier question). The former caches its images whereas the latter does not. I’m not convinced this is your problem here though.What is less clear is where this code fits into your bigger system. I presume the first stretch of code (all the
imageNamed:calls) is in an init method? Is that the case?Is the
//start animationsection really in the same method, or somewhere else. This is not clear because you then include yourtouchesBegan:method in its entirety.You also don’t show where
myimageviewis being created – and who owns it. If you create it within the same class then you should also be releasing it indealloc. Talking ofdeallocit seems to be missing from this version – was that only in the new version? You need it here (more so).I know its hard to post snippets of code unambiguously – but in this case I think these are the things that need clarification.
If your setup code (the
imageNamed:stretch) is being called every time that may well explain it – as might the lack of releasingmyimageview.