在Xcode Analyze下运行我的代码我偶然发现了以下块
- (UIImage *)imageWithFilter:(CIFilter *)filter
{
CIContext *ctx = [CIContext contextWithOptions:nil];
CGImageRef imageRef = [ctx createCGImage:filter.outputImage fromRect:CGRectMake(0, 0, self.size.width, self.size.height)];
return [UIImage imageWithCGImage:imageRef];
}
Xcode抱怨潜在的内存泄漏:
发生了什么事?我将如何解决它?
答案 0 :(得分:10)
以下内容看起来像一个修复程序,仍然不确定这是否是处理此保留引用的最佳方法?
- (UIImage *)imageWithFilter:(CIFilter *)filter
{
CIContext *ctx = [CIContext contextWithOptions:nil];
CGImageRef imageRef = [ctx createCGImage:filter.outputImage fromRect:CGRectMake(0, 0, self.size.width, self.size.height)];
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return image;
}