Memory leak with NSData

Posted by Kamchatka on Stack Overflow See other posts from Stack Overflow or by Kamchatka
Published on 2010-05-01T05:18:24Z Indexed on 2010/05/01 5:27 UTC
Read the original article Hit count: 519

I'm having a leak with this code without being able to find where it's coming from. This function get called within an autorelease pool. I release the IplImage* image argument.

When I run the ObjAlloc tool, it tells me that "NSData* data" is leaking. If I try to manually release the UIImage returned by this function, I get an EXC_BAD_ACCESS error, probably because this UIImage is autoreleased.

I'm a bit confused, any hint would be appreciated.

Thanks!

UIImage *UIImageFromIplImage(IplImage *image)
    {
 NSLog(@"IplImage (%d, %d) %d bits by %d channels, %d bytes/row %s", image->width, image->height, image->depth, image->nChannels, image->widthStep, image->channelSeq);

 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
 NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];
 CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);
 CGImageRef imageRef = CGImageCreate(image->width, image->height,
          image->depth, image->depth * image->nChannels, image->widthStep,
          colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault,
          provider, NULL, false, kCGRenderingIntentDefault);
 UIImage *ret = [UIImage imageWithCGImage:imageRef];
 CGImageRelease(imageRef);
 CGDataProviderRelease(provider);
 CGColorSpaceRelease(colorSpace);
 return ret;
    }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk