Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c presentModalViewController上的内存泄漏_Objective C_Xcode_Memory Leaks_Instruments - Fatal编程技术网

Objective c presentModalViewController上的内存泄漏

Objective c presentModalViewController上的内存泄漏,objective-c,xcode,memory-leaks,instruments,Objective C,Xcode,Memory Leaks,Instruments,我正在打开一个摄像头让用户拍照。 当我拍照并按下“使用”按钮时,我的内存不断泄漏: [自我呈现ModalViewController:imagePicker动画:是] 完整代码: imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; image

我正在打开一个摄像头让用户拍照。 当我拍照并按下“使用”按钮时,我的内存不断泄漏: [自我呈现ModalViewController:imagePicker动画:是]

完整代码:

imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;      
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              (NSString *) kUTTypeMovie, nil];
imagePicker.allowsEditing = NO;

[self presentModalViewController:imagePicker animated:YES]; //This leaks
did使用信息完成PickingMediaWithInfo
ImagePickerControllerIDCancel
中,我都放了这一行:

[imagePicker dismissModalViewControllerAnimated:YES];

我确实知道以前有人问过这个问题,但没有一个问题能进一步帮助我解决泄漏问题。

如果不是ARC环境:

你的
imagePicker=[[UIImagePickerController alloc]init]
返回保留计数+1

然后
[自我呈现Modalviewcontroller:imagePicker动画:是]
保留控制器,因此保留计数+2

[imagePicker DismissModalViewController激活:是]
它是+1,所以您的控制器仍挂在内存中

请在出现Modalviewcontroller后释放控制器

尝试此代码

imagePicker = [[[UIImagePickerController alloc] init] autorelease];
弄清楚你有什么

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

// your code

[pool release];

原来这是iOS本身代码中的一个bug

我下载了苹果开发者网站的示例代码,发现了同样的漏洞。
因此,这将是我自己无法解决的问题,我希望这很快得到纠正。

imagePicker
创建
@property
并分配:

self.imagePicker = [[UIImagePickerController alloc] init];

ARC还是手动内存管理?我确实使用ARC。不,我用的是ARC。使用ARC时有没有办法解决这个漏洞?我在iOS 5.1中工作,所以如果打开ARC,这是不允许的。你确定这是iOS中的错误吗?或者苹果的示例代码也是错误的?因为即使是UIImagePickerController的一个单一组件也没有帮助,仍然会泄漏内存,所以我确信这是iOS本身的一个bug,而不是示例代码中的一个bug。我试过了,但它仍然以完全相同的方式泄漏。