使用 CGImageMaskCreate/imageWithCGImage 应用图像蒙版时出现内存泄漏
这段代码泄露了,有人能告诉我为什么吗?
UIGraphicsBeginImageContext(drawingImage.frame.size);
[drawingImage.image drawInRect:CGRectMake(0, 0, drawingImage.frame.size.width, drawingImage.frame.size.height)];
// Draw some vectorial data
// ...
// Apply an image mask
CGImageRef maskRef = mask.CGImage;
CGImageRef cgmask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([UIGraphicsGetImageFromCurrentImageContext() CGImage], cgmask);
CGImageRelease(cgmask);
drawingImage.image = [UIImage imageWithCGImage:masked];
UIGraphicsEndImageContext();
This code leaks, if someone can tell me why?
UIGraphicsBeginImageContext(drawingImage.frame.size);
[drawingImage.image drawInRect:CGRectMake(0, 0, drawingImage.frame.size.width, drawingImage.frame.size.height)];
// Draw some vectorial data
// ...
// Apply an image mask
CGImageRef maskRef = mask.CGImage;
CGImageRef cgmask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([UIGraphicsGetImageFromCurrentImageContext() CGImage], cgmask);
CGImageRelease(cgmask);
drawingImage.image = [UIImage imageWithCGImage:masked];
UIGraphicsEndImageContext();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“masked”不会被释放,一旦你用它创建了图像,你需要释放它
"masked" is not released, once you created image with it you need to release it