How to Autorelease a CGImageRef?

后端 未结 2 1931
青春惊慌失措
青春惊慌失措 2021-01-06 18:37

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

CGImageRef posterFrame = [avAssetImage copyCGImageAtTime:time actualTim         


        
2条回答
  •  无人及你
    2021-01-06 19:14

    Core Graphics (and Core Foundation) doesn't have an autorelease pool, so if you want to return your CGImageRef you need to either name your function containing Create(f.e. MyCreatePosterImage()) or return UIImage object instead:

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

提交回复
热议问题