Reputation: 13675
Here is the code which I use to present a UIImagePickerController
:
- (IBAction)takePhoto:(UIButton *)sender {
if (![UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"Error", nil)
message:NSLocalizedString(@"Device has no camera", nil)
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok =
[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
style:UIAlertActionStyleDefault
handler:nil];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
} else {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
[self presentViewController:picker animated:YES completion:NULL];
}
}
At the moment I run this method (eg. tap on UIButton
) I can see this in Instruments:
And this is what I see if I change to Cycles & Roots:
So if I hover over the first leak, and press an arrow that pops out, I get this:
and if I open stack trace for this method I see:
So it is mostly system calls. Same goes for other leak, just system calls... So is this a bug or ?? If I open and dismiss image picker few times I get even more leaks, a lot more...
Anybody have noticed this?
Upvotes: 4
Views: 122
Reputation: 827
You need to make UIImagePickerController *picker a strong property. So that app has a global reference to that picker and you will be able to dismiss it.
Upvotes: 1