UIImagePickerController 内存泄漏 [英] UIImagePickerController Memory Leak

查看:48
本文介绍了UIImagePickerController 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 iPhone 应用程序中使用 UIImagePickerController 时,我看到一个巨大的内存泄漏.我正在使用苹果文档中的标准代码来实现控件:

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,但从未发布过.基本上我的 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.

我下载并运行了 Apple 使用 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).

http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010196

您所要做的就是点击照片库按钮并一遍又一遍地点击取消,您会看到内存不断增长.

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 提交报告.我有同样的问题.它也记录在这里: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆