Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 存储在CGImageRef中的对象的潜在泄漏_Ios_Objective C_Xcode_Memory Leaks_Automatic Ref Counting - Fatal编程技术网

Ios 存储在CGImageRef中的对象的潜在泄漏

Ios 存储在CGImageRef中的对象的潜在泄漏,ios,objective-c,xcode,memory-leaks,automatic-ref-counting,Ios,Objective C,Xcode,Memory Leaks,Automatic Ref Counting,在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.s

在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抱怨可能存在内存泄漏:


发生了什么事?我该如何修复它呢?

以下内容看起来像是一个修复,但仍不确定这是否是处理这个过度保留引用的最佳方法

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

这是最好的办法。我可以告诉你:D