5

我将图像的 NSData 转换为 CGImage 如下,但我在那里遇到内存泄漏,但有人告诉我如何转换它而不发生泄漏:

CFDataRef imgData;
CGDataProviderRef imgDataProvider;
CGImageRef image1;
imgData = (CFDataRef)[array objectAtIndex:i];
    imgDataProvider = CGDataProviderCreateWithCFData (imgData);
    image1 = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
4

1 回答 1

10

这应该有效:

CFDataRef imgData;
CGDataProviderRef imgDataProvider;
CGImageRef image1;
imgData = (CFDataRef)[array objectAtIndex:i];
imgDataProvider = CGDataProviderCreateWithCFData (imgData);
CFRelease(imgData);
image1 = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(imgDataProvider);

完成后不要忘记使用CGImageRelease(image1);

于 2012-05-16T09:49:15.920 回答