UIImagePickerController memory leak on iOS5

北战南征 提交于 2019-12-10 05:00:30

问题


i am using UIImagePickerController in my application developing on iOS5 & XCode4.2, getting memory leak and i don't have any idea why i am getting this leak can you please give me the answer for this.

and my code:

-(void)createImagePicker 
{
_picker = [[UIImagePickerController alloc] init];
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;

_picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

_picker.allowsEditing = YES;
_picker.showsCameraControls = NO;


_picker.cameraDevice = UIImagePickerControllerCameraDeviceRear; 

_picker.delegate = self;
_picker.wantsFullScreenLayout = YES;

}

and viewWillApper method:

    -(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeCameraButton:) name:@"ShowMainView" object:nil];
    [self createImagePicker];
    [m_cameraOverlayView setBackgroundColor:[UIColor clearColor]];
    [self presentModalViewController:_picker animated:NO];
    _picker.cameraOverlayView = m_cameraOverlayView;

    [cameraImgView setHidden:YES];
    [filterView setHidden:YES];
    m_cameraOverlayView.hidden = NO;
    cameraSelectedButton.hidden = NO;
    cancelButton.hidden = YES;
    selectButton.hidden = YES;

    for (id Object in [scrollview subviews])
    {
        if([Object isKindOfClass:[UIButton class]])
        {
            [Object removeFromSuperview];
        }
    }

    [m_toolbarImage setFrame:CGRectMake(0, 427, 320, 55)];
    [cameraSelectedButton setFrame:CGRectMake(128, 432, 86, 44)];

    [m_cancelButton setFrame:CGRectMake(10, 434, 82, 40)];
    [m_cancelButton setTitle:@"Close" forState:UIControlStateNormal];
    [m_cancelButton setBackgroundImage:[UIImage imageNamed:@"menu-bar-button.png"] forState:UIControlStateNormal];
    [m_cancelButton setTitleColor:[UIColor colorWithRed:110/256.0 green:52/256.0 blue:28/256.0 alpha:1.0] forState:UIControlStateNormal];


    [cancelButton setFrame:CGRectMake(120, 434, 35, 35)];
    [selectButton setFrame:CGRectMake(184, 434, 35, 35)];

    }

回答1:


This seems to be a problem with UIImagePickerController in iOS 5 whether using ARC or not.

I have an app developed for iOS 4 using xcode 3.2.5 and Instruments shows no leaks when a photo is either taken or selected from the library (tested on a device running iOS 4.1). The same code tested on a device running iOS 5.1 leaks as described.

I know this isn't an answer but the problem seems broader than the original question.




回答2:


Just saw that even the source code from apple linked here leaks with the same problem we have...




回答3:


You should call [_picker release]; to relinquish ownership of _picker memory as described in the Apple Memory Management Docs.




回答4:


I read many other posts about that issue. Someone says that it's an Apple problem, and that's why Zillian suggested that the PhotoPicker example also leaks. The workaround is to create only one instance of UIImagePickerController, probably as a singleton, and to never release it (or let ARC release it for you). In that way you will be using always the same instance and it will probably leak less times.




回答5:


Are you running that app on the simulator? If so, it's a long history problem(or may come back):

The leaks are mostly (but not entirely) on the simulator, and not present on device.

http://blog.airsource.co.uk/index.php/2008/11/12/memory-usage-in-uiimagepickercontroller/



来源:https://stackoverflow.com/questions/10718257/uiimagepickercontroller-memory-leak-on-ios5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!