How to convert NSData images to CGImageRef with memory leaks

I converted the NSData of the image to CGImage, as shown below, but I get memory leaks there, but someone will tell me how to convert this without leaks:

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

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); 

Remember to use CGImageRelease(image1); after you finish with it.

+9
source

Source: https://habr.com/ru/post/1412746/


All Articles