1

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

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

    imagePickerControllerSubject.delegate = self;

    imagePickerControllerSubject.sourceType =  UIImagePickerControllerSourceTypeCamera;

    [self presentModalViewController:imagePickerControllerSubject animated:YES];

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

在此处输入图像描述

我隔离了代码。我确定它来自相机,而不是来自我的应用程序,我在 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
4

1 回答 1

1

在:

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

尝试:

picker.delegate = nil
[self dismissViewControllerAnimated:NO completion:nil];
picker = nil;
于 2013-09-22T14:14:25.320 回答