How is Autorelease CGImageRef?

I have a method that returns an object CGImageRef. It contains this call:

CGImageRef posterFrame = [avAssetImage copyCGImageAtTime:time actualTime:nil error:&error];
...
return posterFrame;

This situation, as I understand it, requires automatic release. But I have no idea how to do this. I tried to use CFCollectable(), but it does not work. Any ideas?

+3
source share
2 answers

If you use garbage collection, use CFMakeCollectable(posterFrame). If you use traditional memory management, this is very simple:

return (CGImageRef)[(id)posterFrame autorelease];

CFTypeRef ( a CGImageRef) Objective-C, -autorelease, CGImageRef. , CFRetain() CFRelease().

+12

Core Graphics ( Core Foundation) , CGImageRef , Create (, MyCreatePosterImage()), UIImage:

CGImageRef posterFrame = [avAssetImage copyCGImageAtTime:time actualTime:nil error:&error];
UIImage *result = [UIImage imageWithCGImage:posterFrame];
CGImageRelease(posterFrame);
return result;
+5

All Articles