使用UIImagePickerController和UIPopoverController两次内存泄漏
这里有一个菜鸟问题。
我有以下代码:
- (IBAction)selectExistingPicture
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
UIPopoverController *popVC = [[UIPopoverController alloc] initWithContentViewController: imagePicker];
popVC.delegate = self;
[popVC setPopoverContentSize:CGSizeMake(320, 100)];
[popVC presentPopoverFromRect:CGRectMake(39, 356, 320, 100) inView:self.view permittedArrowDirections:1 animated:NO];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library" delegate:nil
cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
但编译器警告我两个潜在的内存泄漏。一个用于imagePicker,另一个用于popVC。有人可以解释一下需要改变什么以及为什么。我真的很想知道为什么会这样,所以我将来可以避免它。
谢谢!
没有找到相关结果
已邀请:
1 个回复
疏腔傻小雹
或
,这就是你泄漏的原因。您可以在那里添加自动释放或释放。 选择以下方法之一:
要么
另外,请注意你是如何使用
的。同样的概念。