我UIImagePicker
在我的viewController
,
并且有两种方法我总是会收到内存警告,以及非常有名的“wait_fences:未能收到回复:10004003”,
但我无法追踪到提示警告的特定代码行 - 它总是在这些方法之后立即出现在我无法调试的地方。
// in myViewController.h
// the first 2 are the methods that I alloc my UIImagePicker,
// here, self.photoPicker is a retained property of UIImagePicker.
- (IBAction)fromAlbumButtonTapped {
if (self.photoPicker == nil) {
self.photoPicker = [[[UIImagePickerController alloc] init] autorelease];
self.photoPicker.delegate = self;
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
self.photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.photoPicker animated:YES];
return;
}
}
- (IBAction)fromCameraButtonTapped {
if (self.photoPicker == nil) {
self.photoPicker = [[[UIImagePickerController alloc] init] autorelease];
self.photoPicker.delegate = self;
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:self.photoPicker animated:YES];
return;
}
}
// and this is another part that gives me the memory warning - getting a photo.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
self._photo = [info objectForKey:UIImagePickerControllerOriginalImage];
self.photoView.photoView.image = self._photo;
[self.photoButton setImage:self._photo forState:UIControlStateNormal];
[self dismissModalViewControllerAnimated: YES];
}
我已经检查了我的代码,尽我所能发现没有潜在的内存泄漏。
我知道处理照片确实会占用一些内存,因此出现内存警告是正常的。
但有时问题是,当警告出现时,我viewController
只是release
一些重要的东西,例如用于返回导航堆栈中的 parentView 控制器的一些按钮。
因此,如果我的按钮或其他重要的东西过早释放,我不希望收到内存警告。
有什么办法可以解决吗?