Reputation: 89
Can anyone tell me what is the problem I am having here?
Upvotes: 3
Views: 626
Reputation: 89509
Even though you might have ARC enabled, that only covers Cocoa / Objective-C objects. Core Foundation and Core Graphics API's are different and you still need to eventually explicitly release the memory for any of those objects created as well.
In your code, you are doing a "createCGIImage:
" without a balanced release.
A release looks like:
CGImageRelease(myImageRef)
So, to do this right, do something like:
CGImageRef myImageRef = [context createCGImage: outputImage fromRect: outputImage.extent];
UIImage * imageTemp = [UIImage imageWithCGImage: myImageRef];
CGImageRelease(myImageRef);
Upvotes: 6
Reputation: 5519
The [context createCGImage:fromRect:]
method returns a retained CGImageRef
. The fix your memory leak, you need to save a reference to that CGImageRef
and release it, when you're done with it:
CGImageRef imageRef = [context createCGImage:outputImage fromRect:outputImage.extend];
imageTemp = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
Upvotes: 1
Reputation: 18670
ARC is irrelevant as you are dealing with a CoreFoundation object. You need to assign it to a CGImageRef
variable and then release it with CFRelease(variableName)
.
i.e.
CGImageRef cgImage = [context createCGImage:...];
// rest of your code here
CFRelease(cgImage);
Upvotes: 1