iOS ARC标记为“泄漏”的以下graphics代码

(UIImage *) cropToSquare:(UIImage *)_image { if(_image.size.height < _image.size.width) { CGRect drawRect = CGRectMake(0, 0, _image.size.height, _image.size.height); UIGraphicsBeginImageContext(drawRect.size); CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGRect cropArea = CGRectMake (((_image.size.width - _image.size.height)/2), 0, _image.size.height, _image.size.height); CGContextTranslateCTM(currentContext, 0.0, _image.size.height); CGContextScaleCTM(currentContext, 1.0, -1.0); CGContextDrawImage(currentContext, drawRect, CGImageCreateWithImageInRect (_image.CGImage, cropArea)); UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return cropped; } else { return _image; } 

}

CGContextDrawImage(currentContext,drawRect,CGImageCreateWithImageInRect(_image.CGImage,cropArea))行标记为100%泄漏。

有什么我需要做自己的CG相关的释放?

谢谢

我相信ARC只适用于Cocoa对象,它不适用于Core *框架。

要解决您的泄漏,您需要更改为以下内容:

 CGImageRef myImage = CGImageCreateWithImageInRect (_image.CGImage, cropArea); CGContextDrawImage(currentContext, drawRect, myImage); CFImageRelease(myImage); 

这可能是一个相当大的泄漏,这取决于你的图像的大小。