I'm downloading multiple files like this
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
HUD = [[MBProgressHUD alloc] initWithWindow:self.view.window];
HUD.labelText = @"Downloading";
HUD.mode = MBProgressHUDModeIndeterminate;
[self.view.window addSubview:HUD];
[HUD show:YES];
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
for (NSString *urlString in URLStrings) {
dispatch_group_async(group, queue, ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage *image = [[UIImage alloc] initWithData:data];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error) {
}];
});
}
dispatch_group_notify(group, queue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
HUD.mode = MBProgressHUDModeText;
HUD.labelText = @"Success";
[self performSelector:@selector(hideHUDAndBack) withObject:Nil afterDelay:0.3];
});
});
dispatch_release(group);
And it receives memory warning and shuts down when downloading files with total size of 20MB or more. I tried running it without gcd on the main thread but it still reveived memory warning at the end and shut down. What could be the main cause and how to fix it?