UIImagePickerController内存泄漏 [英] UIImagePickerController Memory Leak
问题描述
在我的iPhone应用中使用 UIImagePickerController
时,我发现内存泄漏很大。我使用apple文档中的标准代码来实现控件:
I am seeing a huge memory leak when using UIImagePickerController
in my iPhone app. I am using standard code from the apple documents to implement the control:
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePickerController animated:YES];
break;
case 1:
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
break;
default:
break;
}
}
对于取消:
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
[picker release];
}
didFinishPickingMediaWithInfo回调就像标准一样,尽管我甚至不需要选择任何导致泄漏的事情。
The didFinishPickingMediaWithInfo callback is just as stanard, although I do not even have to pick anything to cause the leak.
这就是我在仪器中看到的,当我所做的就是打开 UIImagePickerController
,选择照片库,然后反复按取消。正如您所看到的,内存不断增长,最终导致我的iPhone应用程序速度大幅下降。
Here is what I see in instruments when all I do is open the UIImagePickerController
, pick photo library, and press cancel, repeatedly. As you can see the memory keeps growing, and eventually this causes my iPhone app to slow down tremendously.
正如你所看到的那样,我打开了24次图像选择器,每次它都没有发布128kb的malloc。基本上我总共6mb中的3mb从未被释放。
As you can see I opened the image picker 24 times, and each time it malloc'd 128kb which was never released. Basically 3mb out of my total 6mb is never released.
无论我做什么,这个记忆都会被泄露。即使在离开当前控制器之后,仍然保持不变。我还将拾取器控件实现为具有相同结果的单例。
This memory stays leaked no matter what I do. Even after navigating away from the current controller, is remains the same. I have also implemented the picker control as a singleton with the same results.
这是我在深入研究这两行时看到的内容:
Here is what I see when I drill down into those two lines:
非常感谢任何帮助!同样,我甚至不必选择图像。我所做的只是出现控制器,然后按取消。
Any help here would be greatly appreciated! Again, I do not even have to choose an image. All I do is present the controller, and press cancel.
我下载并运行了苹果的示例使用 UIIMagePickerController
,我看到在运行仪器时(在模拟器和手机上)发生同样的泄漏。
I downloaded and ran apple's example of using the UIIMagePickerController
and I see the same leak happening there when running instruments (both in simulator and on the phone).
你所要做的就是点击照片库按钮并反复点击取消,你会看到内存不断增长。
All you have to do is hit the photo library button and hit cancel over and over, you'll see the memory keep growing.
任何想法?
我只在查看照片库时才会看到此问题。我可以选择拍照,一遍又一遍地打开和关闭那张照片,没有泄漏。
I only see this problem when viewing the photo library. I can choose take photo, and open and close that one over and over, without a leak.
推荐答案
这是SDK中的一个错误。向Apple提交报告。我有samme isue。此处还记录了: http:// www .cocoabuilder.com / archive / cocoa / 285293-iphone-memory-leak-can-explain.html
这是一年多以前的事了,但仍无法修复。
It's a bug in the SDK. File a report with Apple. I have the samme isue. It is also documented here: http://www.cocoabuilder.com/archive/cocoa/285293-iphone-memory-leak-can-explain.html and that was over a year ago and still no fix.
这篇关于UIImagePickerController内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!