I add a CAKeyframeAnimation to the ImageView layer to represent the image animation:
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
animation.values = arrayOfImages;
[animation setRemovedOnCompletion:YES];
animation.delegate = self;
[animation setValue:delegate forKey:@"AnimatedImageViewDelegate"];
animation.repeatCount = repeatCount;
animation.fillMode = kCAFillModeForwards;
animation.calculationMode = kCAAnimationDiscrete;
[animation setValue:animationName forKey:@"name"];
When I want to start the animation, I call:
animation.duration = duration;
[self.layer addAnimation:animation forKey:animationName]
[self.layer setContents:[animation.values lastObject]]
When the animation ends, I want to completely remove it and let it go.
[self.layer removeAllAnimations]
[self.layer removeAnimationForKey:animationName]
By doing this and using Monitor-Activity Monitor, memory is not transferred unless I release the full image.
How can I free this animation memory without destroying UIImageView ???
source
share