Since you are saying that you are using the code that you placed inside the loop, I suppose that it happens that your application gets killed because too many automatically allocated objects are allocated inside the loop.
You can try using the auto resource pool:
for (...) { @autoreleasepool { <your code here> } }
so that the autoresist pool is cleared at each iteration (instead of growing throughout the cycle).
EDIT:
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) { ALAssetRepresentation *rep = [result defaultRepresentation]; CGImageRef iref = [rep fullScreenImage]; NSString *tt = [rep filename]; if (iref) { UIImage *image = [UIImage imageWithCGImage:iref]; if(!image) { NSLog(@"---------------------the imageData is nil"); } else { NSData *imageData = UIImagePNGRepresentation(image); NSString *fullPath = [pathPhoto stringByAppendingFormat:@"/%@.png",tt]; NSLog(@"fullPath================%@",fullPath); if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) { [[NSFileManager defaultManager] createFileAtPath:fullPath contents:imageData attributes:nil]; NSLog(@"Creat image file fullPath================%@",fullPath); } } CGImageRelease(iref); } }
source share