iOS - CGImageRef 潜在泄漏
iOS - CGImageRef Potential Leak
我有这个代码:
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *outputimage = [UIImage imageWithCGImage:imageRef
scale:image.scale
orientation:UIImageOrientationUp];
我收到警告:
Object leaked: object allocated and stored into 'imageRef' is not
referenced later in this execution path and has a retain count of +1
但我正在使用 ARC,无法使用 release
或 autoRelease
。如何解决?
只需添加此代码
CGImageRelease(imageRef);
来自 CGImageCreateWithImageInRect
文档,
The resulting image retains a reference to the original image, which means you may release the original image after calling this function.
所以,你需要做的就是调用 CGImageRelease
让它保留计数 -1
我有这个代码:
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *outputimage = [UIImage imageWithCGImage:imageRef
scale:image.scale
orientation:UIImageOrientationUp];
我收到警告:
Object leaked: object allocated and stored into 'imageRef' is not referenced later in this execution path and has a retain count of +1
但我正在使用 ARC,无法使用 release
或 autoRelease
。如何解决?
只需添加此代码
CGImageRelease(imageRef);
来自 CGImageCreateWithImageInRect
文档,
The resulting image retains a reference to the original image, which means you may release the original image after calling this function.
所以,你需要做的就是调用 CGImageRelease
让它保留计数 -1