Running my code under Xcode Analyze i’ve stumbled into the following 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:
What is going on? And how would I go about fixing it?
The following looks like a fix, still not sure if this is the best way of handling this over retained reference?
- (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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With