简体   繁体   中英

CGBitmapContextCreate memory release responsibility

This is how I create a UIImage . I allocated piOutData with calloc. Now when I call CGImageRelease at the end, will it automatically release piOutData or I need to do it manually via free.

int m_iH = iInMaxDim;
int m_iW = iInMaxDim;

UInt8*piOutData = calloc(iInMaxDim *iInMaxDim*4,sizeof(UInt8));
CGContextRef ctx = CGBitmapContextCreate(piOutData,  
                                         m_iW,  
                                         m_iH,  
                                             CGImageGetBitsPerComponent(inImage.CGImage),
                                         m_iW*4,  
                                         CGImageGetColorSpace(inImage.CGImage),  
                                         CGImageGetBitmapInfo(inImage.CGImage) 
                                         ); 
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);  
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

…when I call CGImageRelease at the end, will it automatically release piOutData?

No. piOutData is owned by you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM