Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving big images one after another memory deallocation on iOS
    primarykey
    data
    text
    <p>I have a strange problem while saving number of big images (from camera) to the filesystem one after another in loop. </p> <p>If I place <code>[NSThread sleepForTimeInterval:1.0];</code> in each loop, than memory is released just fine after every image processing. But without that sleep interval, memory allocation increases above the roof and eventually app crashes...</p> <p>Could someone please explain how to avoid this or to deallocate memory after each loop?</p> <p>Btw, I'm developing on iOS 5...</p> <p>This is the my code:</p> <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ for (NSDictionary *imageInfo in self.imageDataArray) { [assetslibrary assetForURL:[NSURL URLWithString:imageUrl] resultBlock:^(ALAsset *asset) { CGImageRef imageRef = [[asset defaultRepresentation] fullResolutionImage]; if (imageRef) { [sharedAppSettingsController saveCGImageRef:imageRef toFilePath:filePath]; imageRef = nil; [NSThread sleepForTimeInterval:1.0]; //CFRelease(imageRef); } } failureBlock:^(NSError *error) { NSLog(@"booya, cant get image - %@",[error localizedDescription]); }]; } // tell the main thread dispatch_async(dispatch_get_main_queue(), ^{ //do smth on finish }); }); </code></pre> <p>And this is the method for saving CGImage to FS:</p> <pre><code>- (void)saveCGImageRef:(CGImageRef)imageRef toFilePath:(NSString *)filePath { @autoreleasepool { CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:filePath]; CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL); CGImageDestinationAddImage(destination, imageRef, nil); bool success = CGImageDestinationFinalize(destination); if (!success) { NSLog(@"Failed to write image to %@", filePath); } else { NSLog(@"Written to file: %@",filePath); } CFRelease(destination); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload