views:

5269

answers:

4

This is driving me crazy!!!

I'm getting a "Received memory warning. Level=1" whenever I attempt to show a UIImagePickerController with a sourceType = UIImagePickerControllerSourceTypeCamera.

Here is the code from my viewDidLoad where I set things up:

    - (void)viewDidLoad {

    [super viewDidLoad];

    // Set card table green felt background
    self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"green_felt_bg.jpg"]];


    // Init UIImagePickerController
    // Instantiate a UIImagePickerController for use throughout app and set delegate
    self.playerImagePicker = [[UIImagePickerController alloc] init];
    self.playerImagePicker.delegate = self;
    self.playerImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}

And here is how I present it modally ..

- (IBAction) addPlayers: (id)sender{
[self presentModalViewController:self.playerImagePicker animated:YES];

}

The result ... UIImagePicker starts to show and then boom ... I get the memory warning ... EVERY TIME! Interestingly enough, if I switch to sourceType = UIImagePickerControllerSourceTypePhotoLibrary ... everything works fine.

What in the heck am I missing or doing wrong? All I want to do is show the camera, take and save a picture.

FYI - I'm testing on my 3GS device.

Thanks to anyone who can help :)

+1  A: 

This is very common. As long as you handle the memory warning without crashing and have enough space to keep going, don't let it drive you crazy.

progrmr
Thanks much! The advice to simply set to nil all your IBOutlets generally found in most text books and classes is just plain wrong (in fact, the descriptions of what you shouldn/shouldn't do in -didReceiveMemory warning sucks too).
wgpubs
+3  A: 

Now after I upgraded to 4.0 it happens to my app too - before in 3.1 there were no warnings.

Actually as you said before, there should be no issue. However, this causes the view that comes after it to load again and viewDidLoad is being called. This messes up my app, since I initialize the view in viewDidLoad - now it gets initialized all over again - even though it shouldn't.

Just as a comment, this might also happen to many other apps that rely on loading the view only once!

This is happening to me now too and is has disastrous consequences for my app. have you been able to solve the issue?
culov
+1  A: 

It did happen in my app Did I Do That on iOS 4.0 too. It was not consistent, but the most common cause was creating a UIImagePickerController instance and navigating to some large photo stored in one of the albums.
Fixed by persisting state in the didReceiveMemoryWarning method, and loading from state in the viewDidLoad method. One caveat is to remember to clear the state-persisted file in the correct point for your application. For me it was leaving the relevant UIViewController under normal circumstances.

DenTheMan
A: 

I'm getting the memory warning when opening a UIImagePickerController as well. I'm on 4.01 as well. But in addition, the UIImagePickerController is running the close shutter animation and stalling there, with the closed shutter on screen.

It seems like the UIImagePickerController's behavior on memory warnings is to close itself. I could dismiss the UIImagePickerController from the parent ViewController in the didReceiveMemoryWarning method, but that would make for a terrible user experience.

Has anyone seen this problem? Is there a way to handle the memory warning so that the UIImagePickerController doesn't shut itself down?

eddy
Hey Eddy, You probably want to pose this as a separate question and post the related code. Here the UIImagePikcerController works as expected except with the "unexpected" memory warning that I was getting ... which in fact appears to be part of its normal operation. Anyhow, if you post a question let me know and I'd be glad to take a look ... I'm more familiar with UIImagePickerController than I ever wished to be :)
wgpubs
Thanks for responding wgpubs. I re-posted my question like you suggested. http://stackoverflow.com/questions/3840234/uiimagepickercontroller-stalls-shut-on-memory-warnings. My idea, which I'm going to be trying today, is to free up more memory in the other ViewControllers to see if that helps the UIImagePicekrController come back to life. Would love to hear your suggestions.
eddy