0

我见过其他线程,但我的似乎更具戏剧性。我正在使用 UIImagePickerController 来允许用户选择或拍摄自己的照片。

这是一些代码:

if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeCamera] == NO))
        return NO;

    ImagePickingViewController *cameraUI = [ImagePickingViewController sharedImagePickingController];
    cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    cameraUI.allowsEditing = NO;

    cameraUI.delegate = self;

    [self presentViewController:cameraUI animated:YES completion:^{
        //do nothing
    }];

一旦执行此操作,我的内存分配就会从 ~3MB 变为 6MB 的活动内存。当我点击取消关闭视图时,内存保持在 6MB!如果我选择一张图片,它会更高,而且会崩溃很多次。

有任何想法吗?

我正在运行 iOS 6 而不是使用 ARC。

[编辑]:这是没有我的类包装器的代码。它做同样的事情 - 显示视图时泄漏 3MB 内存,即使在视图被关闭后也不会返回。

if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeCamera] == NO))
        return NO;

    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    cameraUI.allowsEditing = NO;

    cameraUI.delegate = self;

    [self presentViewController:cameraUI animated:YES completion:^{
        //do nothing
    }];

这是委托方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSLog(@"Image picker finished picking.");
    [self.navigationController dismissViewControllerAnimated:NO completion:^{
        //do nothing
    }];
    [self dismissViewControllerAnimated:NO completion:^{
        //do nothing
    }];

    UIImage *originalImage = (UIImage *)[info objectForKey:
                                    UIImagePickerControllerOriginalImage];
        //Do stuff with image
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [loadingViewController.view removeFromSuperview];
    [self dismissViewControllerAnimated:YES completion:^{
        //Do stuff
    }];
}
4

0 回答 0