Mitesh Dobareeya
Mitesh Dobareeya

Reputation: 1020

GMImagePicker causes application crash

I use GMImagePicker and when i select more than 50 images from camera role the application going to be crash and it gives error like

 Received memory warning.

Please help me to solve this problem. It uses very high memory. The code i did

 - (void)assetsPickerController:(GMImagePickerController *)pickerdidFinishPickingAssets:(NSArray *)assetArray{

    self.requestOptions = [[PHImageRequestOptions alloc] init];
    self.requestOptions.resizeMode   = PHImageRequestOptionsResizeModeExact;
    self.requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

    // this one is key
    self.requestOptions.synchronous = true;

    //  self.assets = [NSMutableArray arrayWithArray:assets];
    PHImageManager *manager = [PHImageManager defaultManager];
    Albumimages = [NSMutableArray arrayWithCapacity:[assetArray count]];

    // assets contains PHAsset objects.
    __block UIImage *ima;

    for (PHAsset *asset in assetArray) {
        // Do something with the asset

        [manager requestImageForAsset:asset
                           targetSize:PHImageManagerMaximumSize
                          contentMode:PHImageContentModeDefault
                              options:self.requestOptions
                        resultHandler:^void(UIImage *image, NSDictionary *info) {
                            ima = image;

                            [Albumimages addObject:ima];

                        }];


    }

NSLog(@"%@",Albumimages);

 [self dismissViewControllerAnimated:YES completion:nil];
}

The application crashed in for loop.

Upvotes: 1

Views: 545

Answers (1)

Rahul Vyas
Rahul Vyas

Reputation: 28740

It will obviously crash as you are picking 50 photos at once. just think in terms of RAM allocation. Lets assume each photo is 5 MB in size so 50*5 MB = 250 MB.OS will not provide enough ram and you are receiving memory warning due to this. See whatsapp and other apps allowed 10 images max. may be you could try the same approach.

Upvotes: 1

Related Questions