Hi,
I'm writing a create CGImageRef from a Path method. This is:
- (CGImageRef)createImage:(NSString*)path
{
// Create NSURL
NSURL *url = [NSURL fileURLWithPath:path];
CFURLRef cfURL = (CFURLRef)url;
// Create image from source
CGImageRef image = NULL;
CGImageSourceRef imageSource = NULL;
imageSource = CGImageSourceCreateWithURL(cfURL, NULL);
if(imageSource != NULL) {
image = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); // LEAK
CFRelease(imageSource);
} else {
NSLog(@"Could not load image");
return NULL;
}
// Scale Image
if(image != NULL) {
// Create context
CGRect rect = CGRectMake(0.0f, 0.0f, CGImageGetWidth(image), CGImageGetHeight(image));
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef context = CGBitmapContextCreate(NULL, rect.size.width,
rect.size.height, 8, 0,
colorSpace,
kCGImageAlphaPremultipliedFirst);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextDrawImage(context, rect, image); // LEAK
CGContextFlush(context);
CGColorSpaceRelease(colorSpace);
CGImageRelease (image);
// Create scaledImage
scaledImage = CGBitmapContextCreateImage(context); // LEAK
image = scaledImage;
CGContextRelease (context);
}
return image;
}
I have turn on Garbage Collector. When I use Instrument, I find leak in CGImageSourceCreateImageAtIndex, CGContextDrawImage and CGBitmapContextCreateImage. Where are the error please? How I should manage the memory in Core Graphics When I turn on Garbage Collector? Thank you and excuse my english.