ios - 存储在 CGImageRef 中的对象的潜在泄漏

标签 ios objective-c xcode memory-leaks automatic-ref-counting

在 Xcode Analyze 下运行我的代码我无意中遇到了以下 block

- (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 提示潜在的内存泄漏:

enter image description here

这是怎么回事?我将如何修复它?

最佳答案

下面看起来像是一个修复,仍然不确定这是否是处理保留引用的最佳方式?

- (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;
}

关于ios - 存储在 CGImageRef 中的对象的潜在泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24325746/

相关文章:

ios - 标签在 UITableView 中没有正确实现,为什么?

ios - 编码 NSMutableArrays 给 NSCoding 错误

ios - 失败并出现错误 1001 "Dropbox SDK v1.3.4"和 "IOS 6.0"

ios - 编译后在 XCode 中编辑 PhoneGap 应用程序

ios - Xcode 6.3 警告

ios - 使用索引进行数字排序

ios - 继续错误 "Ambigious Reference to member ' tableView'“Swift

ios - 从 ViewController 调用 UITableViewDelegate 方法

iphone - 架构 i386 的 undefined symbol 将项目升级到 iOS 5

ios - 使用 CHCSV 解析器时出错 : No known class method for selector 'arrayWithContentsOfCSVFile:encoding:error:'