使用CGImageMaskCreate / imageWithCGImage应用图像蒙版时内存泄漏

时间:2010-07-01 12:20:23

标签: iphone memory-leaks uiimage core-graphics

如果有人能告诉我原因,这段代码会泄漏?

    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();

1 个答案:

答案 0 :(得分:4)

“蒙面”未发布,一旦您使用它创建图像,则需要将其释放

drawingImage.image = [UIImage imageWithCGImage:masked];
CGImageRelease(masked)