iphone - 删除 CAKeyframeAnimation 不会释放内存

标签 iphone cocoa-touch uiimageview core-animation cakeyframeanimation

我将 CAKeyframeAnimation 添加到 ImageView 层以表示图像的动画:

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"];

当我想开始动画时,我调用:

animation.duration = duration;
[self.layer addAnimation:animation forKey:animationName];
[self.layer setContents:[animation.values lastObject]];

当动画结束时,我想完全删除它并释放它的内存。

[self.layer removeAllAnimations];       
[self.layer removeAnimationForKey:animationName];

这样做并使用 Instruments-Activity Monitor,除非我释放完整的 imageView,否则内存不会释放。

如何在不破坏 UIImageView 的情况下释放动画内存???

最佳答案

您正在使用便捷方法来实例化该对象。因此您将无法控制对象何时被实际释放。要对此进行控制,您需要自己分配对象并释放它:

创建实例:

CAKeyframeAnimation *animation = [[CAKeyframeAnimation alloc] init];

然后在动画完成后,在删除行后调用:

[animation release];

关于iphone - 删除 CAKeyframeAnimation 不会释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022015/

相关文章:

iphone - NSString stringWithFormat 很慢

iphone - 在 Objective-C 中将 TypeDef 作为参数

iphone - 在 UIScrollView 中使用 UIImageView 或 UIButton 时出现问题

ios - 如何在 xcode 4.5 的 UIscrollview 中显示图像边框?

iphone - 链接到 Itunes 商店中的应用程序

javascript - 如何强制网页脱离 native 移动应用程序?

iphone - 为什么我的 XIB 文件无法本地化 (iPhone)?

iphone - 我的自定义类中未调用 Touches Began 方法

ios - AFNetworking UIImage NSURL

ios - Xcode : Image taken from camera directly placed in UIImageView