imageWithCGImage and memory

前端 未结 8 408
既然无缘
既然无缘 2020-12-10 02:24

If I use [UIImage imageWithCGImage:], passing in a CGImageRef, do I then release the CGImageRef or does UIImage take care of this itse

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 02:50

    Not sure if this helps, but I had a similar problem. I read the answers and then did the following which appears to have fixed it:

    CGImageRef cgImage = [asset thumbnail];
        UIImage *thumbImage = [[UIImage imageWithCGImage:cgImage ]retain];
        UIImageView *thumbImageView = [[UIImageView alloc] initWithImage:thumbImage];
        CGImageRelease(cgImage);
    

    I used the autorelease as suggested but it was not enough. One I had added the image to the UIImageView I then released the cgImage.
    It didn't crash and deallocated nicely. Why -- I have no idea but it worked.

    The asset thumbnail part is from the ALAsset Library by the way, you might need something else there.

提交回复
热议问题