I am trying to figure out why when my application gets a didReceiveMemoryWarning while the UIImagePickerController has control, the picker (and thus the delegate of the picker) is set to the deallocated viewcontroller?
View Controller one calls
self.postImagePicker = [[UIImagePickerController alloc] init];
self.postImagePicker.delegate = self;
self.postImagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
self.postImagePicker.allowsEditing = YES;
[self presentModalViewController:self.postImagePicker animated:YES];
Next, the UIImageViewController is displayed and an image is selected. Then simulate a memory warning. The view controller that presented the dialog gets a memory warning error and the picker is set to 0x0 (which means that the delegate is also now invalid).
I'm using ARC. Has something changed in the way that an UIImageViewController is called so that the view that presented it is not reloaded thus causing the pointer to the UIImageViewController to become invalid?
Check
didReceiveMemoryWarning
. Do you haveself.postImagePicker = nil;
there? Check thedidReceiveMemoryWarning
methods for your upstream view controllers. Do they have a reference to this view controller? If not, the navigation controller may be dumping this view controller.delegate
is a weak reference, so it's not enough to keep your view controller around if nothing else is.