【发布时间】:2014-06-17 03:16:06
【问题描述】:
xcode 分析器说在使用 CGContextClip 时存在存储到“路径”上的潜在内存泄漏。什么会导致这种潜在的内存泄漏?
- (UIImage *)imageMaskToEllipseWithBorderWidth:(float)boarderWidth andBorderColor:(UIColor *)borderColor
{
UIGraphicsBeginImageContextRetinaAware( self.size );
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef path = CGPathCreateWithEllipseInRect(CGRectMake(0, 0, self.size.width, self.size.height), NULL);
CGContextAddPath(context, path);
CGContextClip(context); // *** Warning is shown here during static analysis ***
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
if( boarderWidth > 0 && borderColor != nil )
{
[borderColor set];
CGContextSetLineWidth(context, 2.0);
CGContextStrokeEllipseInRect(context, CGRectMake(0, 0, self.size.width, self.size.height));
}
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
【问题讨论】:
-
您可以点击右侧“潜力...”之前的蓝色图标。 Xcode 会告诉你它是如何泄露的。
标签: objective-c xcode memory-leaks static analysis