呈现UIImagePickerController时检测到泄漏

时间:2017-01-31 12:00:59

标签: ios objective-c xcode memory-leaks xcode-instruments

以下是我用来展示- (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

目前我运行此方法(例如点击:parent has_many :kids :kid has_many :schools @parent = Parent(parent_params) @parent = HTTParty.post("http://localhost:3001/parents/import", :body => { :parent_id => @parent.id, :terms_accepted => @parent.terms_accepted, :email => @parent.email, :kids => { @parent.kid.school.name => @parent.kid.school_name, @parent.kid.age => @parent.kid.age } }.to_json, :headers => { 'Content-Type' => 'application/json' } ) )我可以在乐器中看到这一点:

Leaks By Backtrace

如果我换成Cycles&根:

Cycles and Roots

因此,如果我将鼠标悬停在第一次泄漏上,按下弹出的箭头,我就明白了:

enter image description here

如果我为这个方法打开堆栈跟踪,我会看到:

enter image description here

所以主要是系统调用。同样适用于其他泄漏,只是系统调用......所以这是一个bug还是?如果我几次打开和关闭图像选择器,我会得到更多泄漏,更多......

有人注意到了吗?

1 个答案:

答案 0 :(得分:1)

你需要使UIImagePickerController * picker成为一个强大的属性。因此,该应用程序具有对该选择器的全局引用,您将能够将其解除。