UIImagePickerController Memory Leak

前端 未结 5 1195
日久生厌
日久生厌 2020-12-03 08:49

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:<

相关标签:
5条回答
  • 2020-12-03 09:25

    Try setting the UIImagePickerController.delegate to nil before releasing.

    -(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
    {
        [[picker parentViewController] dismissModalViewControllerAnimated: YES];
        picker.delegate = nil;
        [picker release];
    }
    
    0 讨论(0)
  • 2020-12-03 09:32

    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.

    0 讨论(0)
  • 2020-12-03 09:35

    I used UIImagePickerController and after 40 capture images my application received a DidMemoryWarning message and stop, hidden all my views.

    In my application I create 40 objects of

    UIImagePickerController( new UIImagePickerController() )
    

    To work correctly I create a unique instance shared to all application and with this all work correctly.

    I supusose that control lost memory too, but only one time. My application can capture images from camera correctly:

    private static UIImagePickerController picker = new UIImagePickerController();
    
    0 讨论(0)
  • 2020-12-03 09:45

    A few of our apps reuse the same UIImagePickerController due to a leak in 2.x (it makes me feel old...). I was under the impression that the leak was fixed, but I could be wrong.

    It's a slightly horrible workaround, but sometimes that's the best you can do.

    0 讨论(0)
  • 2020-12-03 09:45

    The "Mark Heap" button in Instruments has been, for me, the absolute best way of tracking down these sorts of issues.

    This is an OK article on how to use it: http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/

    But it will tell you, for sure, which objects are surviving longer than you expect... and, ultimately, what the source of the issue is.

    You can also see a complete retain/release trace for each individual object which survived - allowing you to pinpoint where your problem is.

    EDIT: I use a UIImagePickerControllers as well, and I can promise it doesn't leak (at lesat for me) the way you're suggesting - so, whatever is going on, it's almost surely fixable.

    0 讨论(0)
提交回复
热议问题