【发布时间】:2011-12-08 21:55:53
【问题描述】:
我有这个代码:
- (CGImageRef)createImageWithContext:(CGContextRef)context
{
return CGBitmapContextCreateImage(context);
}
- (void)fooWithContext:(CGContextRef)context
{
CGImageRef imgRef = [self createImageWithContext:context];
CGImageRelease(imgRef);
}
这是一个在 Xcode 中构建并启用 ARC 的 Objective-C 项目。 Build and Analyze 报告了两个错误:一个在 CGBitmapContextCreateImage 行上识别潜在泄漏,另一个在 CGImageRelease 上,指出“调用者此时不拥有的对象的引用计数不正确递减”。
如果我将这两个功能合二为一:
- (void)fooWithContext:(CGContextRef)context
{
CGImageRef imgRef = CGBitmapContextCreateImage(context);
CGImageRelease(imgRef);
}
我没有收到任何警告。
静态代码分析错误?还是我在这里遗漏了什么?
【问题讨论】:
标签: objective-c automatic-ref-counting