Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert NSData of image to CGImageRef with out memory leaks

i converted NSData of image to CGImage as below but i am getting memory leaks there but any one tell me how to convert that with out getting leaks:

CFDataRef imgData;
CGDataProviderRef imgDataProvider;
CGImageRef image1;
imgData = (CFDataRef)[array objectAtIndex:i];
    imgDataProvider = CGDataProviderCreateWithCFData (imgData);
    image1 = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
like image 777
Steve Gear Avatar asked May 16 '12 09:05

Steve Gear


1 Answers

This should work:

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

Don't forget to use CGImageRelease(image1); after you are done with it.

like image 79
Christoph Winkler Avatar answered Oct 21 '22 19:10

Christoph Winkler