views:

376

answers:

1

I use a UIPickerViewController to take picture. It works 80% but seemingly at random it fails to take a picture. In tracing the code I found out that it occasionally goes to

-PinRecordNewTableViewController:viewDidUnload. 

That is where it fails because it set nil to all ivars.

@interface PinRecordNewTableViewController : UITableViewController {
}
... 
@implementation PinRecordNewTableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
...
        PinRecordNewPicture *pinRecordNewPicture = [[PinRecordNewPicture alloc] initWithNibName:@"PinRecordNewPicture" bundle:nil];
        pinRecordNewPicture.delegate = self;
        [self.navigationController pushViewController:pinRecordNewPicture animated:YES];    
        [pinRecordNewPicture release];  
...             
}
@interface PinRecordNewPicture : UIViewController 
...
@implementation PinRecordNewPicture
...
- (void)picturePicker:(UIImagePickerControllerSourceType)theSource {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;
picker.sourceType = theSource;
picker.allowsEditing = YES;

[self presentModalViewController:picker animated:YES];

[picker release];
}

- (IBAction) takePicture:(id)sender {

UIImagePickerControllerSourceType source = UIImagePickerControllerSourceTypeCamera;

    if ([UIImagePickerController isSourceTypeAvailable:source]) {

       [self picturePicker:source];

    }

What did I do wrong? Did I miss something that causes it to behave "randomly"?

Thanks in advance for your help.

A: 

If it called viewDidUnload, then it is very likely that your app is running out of memory. This could be a problem, or just the result of editing large images in phone.

Paul Lynch
I just take a regular picture. Will it help if I set "picker.allowsEditing = NO;" ?
pion
Yes, almost certainly, unless you have a bad leak somewhere else.
Paul Lynch
I have just run XCode -> Run -> Run With Performance Tool -> Leaks. It says that I have a leak on the following code specifically on line "UIImagePickerController *picker = [[UIImagePickerController alloc] init];".But I don't understand why.Do I do something wrong?- (void)picturePicker:(UIImagePickerControllerSourceType)theSource { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = theSource; picker.allowsEditing = NO; [self presentModalViewController:picker animated:YES]; [picker release];}
pion
You alloc then release in the same method - so there's no leak. Instruments sometimes can't tell, and sometimes gets it wrong.
Paul Lynch
"UIImagePickerControllerSourceTypeCamera hogging up memory" - http://stackoverflow.com/questions/565886/uiimagepickercontrollersourcetypecamera-hogging-up-memory - explains my problem
pion