views:

242

answers:

1

I am getting a "Received memory warning. Level = 1" when I use UIImagePickerControllerSourceTypeCamera.

If i access the camera immediately after entering the application, I get "Received memory warning. Level=1" but when i select the camera option after accessing all the other functionality in the application, the app crashes while the debugger console displays

Received memory warning. Level=1 Program received signal: “EXC_BAD_ACCESS”.

Why does this happen? I don't get any memory leaks notification when I build and analyze.

 if(actionSheet.tag == 1){
      addButton.enabled = YES;
      UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
      picker.delegate = self;

      if (buttonIndex == 0)
      {

         NSLog(@"selecting camera"); 
         picker.sourceType = UIImagePickerControllerSourceTypeCamera;

         [self presentModalViewController:picker animated:YES];  
      }
      else if (buttonIndex == 1){

          NSLog(@"choosing album");
          picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
          [self presentModalViewController:picker animated:YES];
      }
      else
      {
          //NSLog(@"cancel");
      }

  }
A: 

EXC_BAD_ACCESS normally is the opposite of a leak: An overreleased object. An object which retain count has dropped to 0 but you still hold a pointer to it somewhere. Once you access this pointer you may receive EXC_BAD_ACCESS, or other strange behavior.

There's other possibilities, too. It just means your trying to access memory, that you do not own.

In your case this does not necessarily have to do with the UIImagePickerController. The presenting of the picker just causes a memory warning to be posted, and in reaction to this warning your app releases memory in various different places. My guess is, that at least one of these objects has already been released before, and is a dangling pointer now.

To debug this you should try NSZombieEnabled. See this question for further help on finding this kind of bug: http://stackoverflow.com/questions/327082/exc-bad-access-signal-received

P.S.: You should have found it when searching for for EXC_BAD_ACCESS

tonklon
i did use the zombie feature using instruments and also using NSZOmbieEnabled. It didn't notify me. To be more specific, I have two different view controllers, one viewcontroller has the uiimagepicker and the other has a "text". I also noticed that I receive the EXC_BAD_ACCESS signal only after I switch back from "text" view controller to UIImagepicker view controller. I don't receive the bad access signal when i start with UIImagepicker view controller.
Praveen
Then it's possibly not an overreleased object. Are you mallocing any any memory, anywhere? Can you post a stack trace and the code around the line where you receive the signal?
tonklon