从UIImagePickerControllerSourceTypeCamera拍摄照片后内存泄漏

时间:2013-09-22 10:03:37

标签: ios memory-leaks ios7 ios-camera

在我的应用程序中,我启动相机让用户拍照:

    UIImagePickerController *imagePickerControllerSubject = [[UIImagePickerController alloc] init];

    imagePickerControllerSubject.delegate = self;

    imagePickerControllerSubject.sourceType =  UIImagePickerControllerSourceTypeCamera;

    [self presentModalViewController:imagePickerControllerSubject animated:YES];

拍完照片后,我收到内存泄漏,你可以看到Xcode Instrument的截图。

enter image description here

我隔离了代码。我确定它来自相机,而不是来自我的应用程序,我在didFinishPickingImage函数中没有留下任何内容。

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {

           [picker dismissModalViewControllerAnimated:YES];

           return;

    }

我使用ARC所以我不需要发布imagePickerControllerSubject

以下是Xcode Instruments的截图

我使用最新版本的ios7

有什么想法吗?

由于

修改

我在这里查看了我的视图控制器的整个代码。它不能简单。并且不要忘记,只有在iOS 7中才会出现此内存泄漏,并且仅在源类型为相机时才会泄漏。

    #import "FeedbackVC.h"

    @interface FeedbackVC ()

    @end

    @implementation FeedbackVC

    - (IBAction)onClickTakePicture
    {

        NSLog(@"onClickTakePicture");

        imagePickerControllerSubject = [[UIImagePickerController alloc] init];

        imagePickerControllerSubject.delegate = self;

        imagePickerControllerSubject.sourceType =               UIImagePickerControllerSourceTypeCamera;

        [self presentModalViewController:imagePickerControllerSubject animated:YES];

    }

     - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
     {


         picker.delegate = nil;
         [self dismissViewControllerAnimated:NO completion:nil];
         picker = nil;

         NSLog(@"imagePickerController");

     }

     - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
     {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self)
        {
            // Custom initialization
            if (self)
            {
              self.navigationItem.title = @"Feedback";

              self.title = @"Feedback";

              self.tabBarItem.image = [UIImage imageNamed:@"second"];
            }

        }


        return self;
    }

    - (void)viewDidLoad
    {
       [super viewDidLoad];

    }

     - (void)didReceiveMemoryWarning
     {
          [super didReceiveMemoryWarning];
          // Dispose of any resources that can be recreated.
     }

     @end

1 个答案:

答案 0 :(得分:1)

在:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

尝试:

picker.delegate = nil
[self dismissViewControllerAnimated:NO completion:nil];
picker = nil;