【发布时间】:2017-06-16 20:36:44
【问题描述】:
这是我用来展示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];
}
}
目前我运行这个方法(例如点击UIButton)我可以在仪器中看到这个:
如果我更改为 Cycles & Roots,这就是我看到的:
因此,如果我将鼠标悬停在第一个泄漏上,然后按下弹出的箭头,我会得到:
如果我打开此方法的堆栈跟踪,我会看到:
所以它主要是系统调用。其他泄漏也是如此,只是系统调用......所以这是一个错误还是?如果我打开并关闭图像选择器几次,我会得到更多的泄漏,更多......
有人注意到了吗?
【问题讨论】:
-
正如我在bisma's answer 的评论中已经提到的,在回调方法中我只有一个关闭选择器的代码:
[picker dismissViewControllerAnimated:YES completion:nil];
标签: ios objective-c xcode memory-leaks xcode-instruments