micky
micky

Reputation: 23

Received memory warning. with ipad camera

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.

Upvotes: 2

Views: 2346

Answers (3)

user2703543
user2703543

Reputation: 44

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.

Upvotes: 2

user2702717
user2702717

Reputation: 1

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]
}

Upvotes: 0

Muhammed Ayaz
Muhammed Ayaz

Reputation: 1398

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.. :-)

Upvotes: 3

Related Questions