創建一個巨大的分配我試圖動畫的UIImage
與CAKeyframeAnimation
數組的動畫。理論上很簡單。
帖子底部的示例代碼。CAKeyframeAnimation - 動畫的圖像數組創建後完成
我的問題是,動畫完成後,我有一個巨大的泄漏,不可能擺脫它。
代碼以初始化CAKeyframeAnimation
:
- (void)animateImages
{
CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
keyframeAnimation.values = self.imagesArray; // array with images
keyframeAnimation.repeatCount = 1.0f;
keyframeAnimation.duration = 5.0;
keyframeAnimation.removedOnCompletion = YES;
CALayer *layer = self.animationImageView.layer;
[layer addAnimation:keyframeAnimation
forKey:@"flingAnimation"];
}
添加委託到動畫和去除動畫手動引起同樣的泄漏的效果:
... // Code to change
keyframeAnimation.delegate = self;
// keyframeAnimation.removedOnCompletion = YES;
keyframeAnimation.removedOnCompletion = NO;
keyframeAnimation.fillMode = kCAFillModeForwards;
....
然後:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if (flag)
{
[self.animationImageView.layer removeAllAnimations];
[self.animationImageView.layer removeAnimationForKey:@"flingAnimation"]; // just in case
}
}
結果是a佔據巨大的份額。的存儲器堆的大小正比於圖像的大小:
I uploaded an example to GitHub to check the code.
我運行儀器,沒有泄漏,但分配很高。 – gabbler
你有什麼想法如何解決高配置? –
改爲使用'imageWithContentsOfFile'。 – gabbler