2
다음 코드 스 니펫은 UIImage
을 사용하여 디스크에 CIImage
을 저장합니다.메모리 누수없이 iOS의 파일에 CIImage를 저장할 수 없습니다.
- (void)applicationWillResignActive:(UIApplication *)application
{
NSString* filename = @"Test.png";
UIImage *image = [UIImage imageNamed:filename];
// make some image processing then store the output
CIImage *processedImage = [CIImage imageWithCGImage:image.CGImage];
#if 1// save using context
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgiimage = [context createCGImage:processedImage fromRect:processedImage.extent];
image = [UIImage imageWithCGImage:cgiimage];
CGImageRelease(cgiimage);
#else
image = [UIImage imageWithCIImage:processedImage];
#endif
// save the image
NSString *filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[@"../Documents/" stringByAppendingString:filename]];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
}
그러나, UIImage
거기 CIImage
로부터 직접 생성되며 #if 1
와 라인 #if 0
으로 변경되는 경우가 CGImageRelease
호출하여 해제시에도 CGImageRef
누출 메모리 누수가 없지만 UIImage
은 디스크에 저장되지 않습니다.
@autoreleasepool을 사용해도 문제가 해결되지 않습니다. http://stackoverflow.com/questions/32685756/memory-leak-in-cmsamplebuffergetimagebuffer – loretoparisi