Potential leak of object stored in CGImageRef

Running my code in Xcode Analyze ive came across the next 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 complains about a potential memory leak:

enter image description here

What's happening? And how can I fix it?

+6
source share
1 answer

The following looks like a fix, but not sure if this is the best way to handle this saved link?

 - (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; } 
+9
source

Source: https://habr.com/ru/post/971092/


All Articles