2
votes

When i open Camera in my app it works fine, but when i navigate in my app and comes back to camera view and again try to open my camera in iPad, app crashes and gives me "Received memory warning". app working fine in iPhone and this issues is only coming in iPad.

My project was without ARC so i converted my project into ARC in the hope to get good results but still my app crashes on camera after little navigation. can anybody tell me how to decrease memory space with iPad camera so that my apps stop receiving memory warning.

this is my code for camera

if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        imagePicker=[[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
        imagePicker.allowsEditing = NO;
        //imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentViewController:imagePicker animated:YES completion:nil];
   } 

This is where I get my Image

-(void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info
{
        [Array removeAllObjects];

        [picker dismissViewControllerAnimated:YES completion:nil];
        image = [info objectForKey:UIImagePickerControllerOriginalImage];

        [array addObject:image];
        image=nil;

}

and i have also try to use popOverview for camera but it also didn't work.

In my viewController where I'm calling UIImagePickerController I have used 5 animations, before i was calling animation in viewWillAppear, and app was crashing so i changed Animation calling to ViewDidLoad and camera starting working but only until I navigate to my last view and comes back to open camera again.

3
The problem is not the camera. You are probably not discarding the used and unnecessary objects properly. - Desdenova
Are you using the iOS default camera picker or connecting the camera to a preview layer or e.g. are you processing each video buffer using OpenGL or CoreImage? - Markus
@Desdenova I m using ARC now, so how could i release objects. - micky
@Markus No bro I m opening camera not using openGL - micky

3 Answers

2
votes

Try to run your app without animation and then try, if it works then you need to improve your animations memory allocation, as animation needs a lot of memory.

3
votes

I am getting same problem so i do like this.

Set UIImagePickerController as static like this.

 static UIImagePickerController *imagePicker;

When you get image in this deleget.

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
  @autoreleasepool {// to release memory

   // Probelm is you image size. 
   // When you get this image it is vary large.
   // And i hope  you are creating multiple copy's of this image.

   // when you get image in 
   UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    // In last set image as nil
   image = nil;
  }
}

Hope this will solve you problem.. :-)

0
votes

Please try below code.try UIImagePickerController with in popover

if([UIImagePickerContrller isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        controller.allowsEditing = YES;
        controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        controller.delegate = self;
        UIPopoverController *popController = [[UIPopoverController alloc]  initWithContentViewController:controller];
        popController.popoverContentSize = CGSizeMake(350.0f, 500);
        [popController presentPopoverFromRect: self.button.frame inView:self.button.superview
                     permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]
}