有什么可以帮助我理解为什么我在运行analyze时遇到这个问题?
我可能会泄漏存储在“oldShadowPath”中的对象。
-(void) layoutShadowWithDuration:(NSTimeInterval)duration
{
CGPathRef oldShadowPath = self.mainViewController.view.layer.shadowPath;
if (oldShadowPath)
{
CFRetain(oldShadowPath);
}
// Update shadow path for the view
CGPathRef path = [UIBezierPath bezierPathWithRect:self.mainViewController.view.bounds].CGPath;
self.mainViewController.view.layer.shadowPath = path;
// You would think setting duration to 0 would cause the animation added below to not animate. You would be wrong.
if (duration != 0) {
if (oldShadowPath)
{
[self.mainViewController.view.layer addAnimation:((^ {
CABasicAnimation *transition = [CABasicAnimation animationWithKeyPath:@"shadowPath"];
transition.fromValue = (__bridge id)oldShadowPath;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.duration = duration;
return transition;
})()) forKey:@"transition"];
CFRelease(oldShadowPath);
}
}
}
答案 0 :(得分:1)
这是因为您没有与每个CFRetain相对应的CFRelease。您在double'if'语句中释放对象,其中一个语句独立于保留条件(“oldShadowPath”)。
答案 1 :(得分:-1)
正如@ H2CO3评论的那样,如果duration
为0,那么oldShadowPath
永远不会被释放。