English 中文(简体)
UIImaage Picker 控制器在 iOS5 上内存泄漏
原标题:UIImagePickerController memory leak on iOS5

我使用 UIImagePicker 控制器来开发 iOS5 & amp; XCode4.2 的应用程序, 导致内存泄漏, 我完全不知道为什么要泄露这个信息, 请给我答案。

"https://i.sstatic.net/qHmSw.png" alt="在这里我附上我的屏幕镜头:"/"

和我的代码:

-(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;

}

并查看 WillApper 方法 :

    -(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)];

    }
问题回答

这似乎与IOS 5中的UIImagePicker主计长有问题, 不论是否使用 ARC 。

我开发了一个应用软件,用于使用 xcode 3.2.5 的iOS 4, 当从图书馆拍摄或选择照片时, 仪器没有显示泄漏( 在运行 iOS 4. 1 的设备上测试) 。 在运行 iOS 5. 1 的 iOS 5. 1 泄漏设备上测试的代码相同 。

我知道这不是一个答案,但问题似乎比最初的问题更广泛。

您应该调用 [_picker report]; 放弃苹果内存管理文档中描述的对_picker内存的所有权。

我读了许多其他有关这个问题的文章。有人说这是一个苹果问题,而Zillian则建议PhotoPicker的例子也会泄漏。 工作上的变通就是只创建一个UIImagePicker主计长(也许作为一个单吨)的例子,并且永不释放(或者让ARC为您发布 ) 。 这样,你就会总是使用同样的例子,它可能会减少泄漏次数。

您正在模拟器上运行此应用程序吗? 如果是的话, 这是一个很长的历史问题( 或可能回来 ) :

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

http://blogy.airsource.co.uk/index.php/2008/11/12/memory-usage-in-uimagepricker control/





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签