我正在分析我的应用并收到以下警告。有人可以帮我解决这个问题吗?所有其他错误都消失了。
以下是代码:
- (void)drawInContext:(CGContextRef)context
{
if (!self.isPresentationLayer) {
self.contentsScale = [[UIScreen mainScreen] init].scale;
}
CGMutablePathRef path = CGPathCreateMutable();
self.mainPath = (CGMutablePathRef)CGPathCreateCopy(path);
CGContextSaveGState(context);
[self customDrawInContext:context];
[self drawMainPathImageInContext:context];
CGContextRestoreGState(context);
CGPathRelease(path);
self.isAllowedToAnimate = YES;
}
这是警告信息:
1。)调用功能' CGPathCreateCopy'返回具有+1保留计数的Core Foundation对象
2。)对象泄露:此执行路径中未引用已分配的对象,并且保留计数为+1
答案 0 :(得分:0)
我认为问题在于:
self.contentsScale = [[UIScreen mainScreen] init].scale;
首先,您不需要init
,因为主屏幕是UIScreen
类的静态属性。只写:
self.contentsScale = [UIScreen mainScreen].scale;
接下来,我认为问题与您的媒体资源存储类型有关。
当你写:
- (void)drawInContext:(CGContextRef)context
{
if (!self.isPresentationLayer) {
self.contentsScale = [[UIScreen mainScreen] init].scale;
}
CGMutablePathRef path = CGPathCreateMutable();
// path as +1 retainCount because of 'create'
self.mainPath = (CGMutablePathRef)CGPathCreateCopy(path);
// self.mainPath as +1 retainCount because of 'copy'
// self.mainPath as again +1 retainCount if the property storage type is retain, copy or strong (I think the error is here)
CGContextSaveGState(context);
[self customDrawInContext:context];
[self drawMainPathImageInContext:context];
CGContextRestoreGState(context);
CGPathRelease(path);
// path as -1 retainCount and so is released.
self.isAllowedToAnimate = YES;
}