views:

39

answers:

1

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();
+1  A: 

"masked" is not released, once you created image with it you need to release it

drawingImage.image = [UIImage imageWithCGImage:masked];
CGImageRelease(masked)
Alexander Voloshyn
Correct! Thanks a lot
Sébastien Gruhier
Sébastien Gruhier: If Alexander Voloshyn's answer is the correct one, then you should accept it as such by clicking on the checkmark. This rewards him for posting a correct answer, and indicates the answer's correctness to future readers of this question.
Peter Hosey