opencv IplImage与ARC泄漏的UIImage

时间:2011-10-16 13:46:45

标签: iphone opencv uiimage memory-leaks

我正在使用此功能将IplImages流转换为UIImage:

 +(UIImage *)createUIImageFromIplImage:(IplImage *)image
{       
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);

    CGImageRef imageRef = CGImageCreate(image->width, image->height,
                                       image->depth, image->depth * image->nChannels, image->widthStep,
                                       colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault,
                                       provider, NULL, false, kCGRenderingIntentDefault);

    UIImage* ret = [UIImage imageWithCGImage:imageRef];

    CGImageRelease(imageRef);
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpace);

    return ret;
}

然而,在几张图像然后崩溃后,我收到内存警告。在乐器中运行意味着有问题的行是分配内存的地方:

NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];

不知何故,这个记忆永远不会被释放。 如何解决这个问题?

0 个答案:

没有答案