gpt4 book ai didi

ios - 我从 UIImagePickerControllerSourceTypeCamera 拍照后内存泄漏

转载 作者:行者123 更新时间:2023-11-29 13:04:42 25 4
gpt4 key购买 nike

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

    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

有什么想法吗?

谢谢

编辑

我在这里传递了我的 View Controller 的全部代码。再简单不过了。并且不要忘记我只在 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

最佳答案

在:

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

尝试:

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

关于ios - 我从 UIImagePickerControllerSourceTypeCamera 拍照后内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18942623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com