I'm adding a CAKeyframeAnimation to the layer of an ImageView for representing the animation of an image:
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 finishes, I want to completely remove it and release its memory.
[self.layer removeAllAnimations];
[self.layer removeAnimationForKey:animationName];
Doing this, and using Instruments-Activity Monitor, the memory is not relased unless I release the complete imageView.
How can I release that animation memory without destroy the UIImageView???