简体   繁体   English

CGBitmapContext创建内存释放责任

[英]CGBitmapContextCreate memory release responsibility

This is how I create a UIImage . 这就是我创建UIImage I allocated piOutData with calloc. 我用calloc分配了piOutData Now when I call CGImageRelease at the end, will it automatically release piOutData or I need to do it manually via free. 现在,当我最后调用CGImageRelease时,它将自动释放piOutData还是我需要通过免费手动进行操作。

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? …当我最后调用CGImageRelease时,它将自动释放piOutData吗?

No. piOutData is owned by you. piOutData由您拥有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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