使用相机的 UIImagePickerController 出现严重内存问题
我注意到,当我加载 UIImagePickerController 并用它拍照时,会调用 didReceiveMemoryWarning
。另外,在 Instruments 中,存在严重的内存泄漏(不是我造成的,我发誓!)。我听说这是 UIImagePickerController 的问题,但是我不知道如何解决它。这是我的 UIImagePickerController 实现。
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; // Create the imagePicker
imagePicker.delegate = self;
imagePicker.allowsEditing = YES; // Allow editing of the images
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
有什么想法吗?我真的不想牺牲这么有用的功能。
I've noticed that when I load a UIImagePickerController and I take a picture with it, didReceiveMemoryWarning
is called. Also, in Instruments, there is a significant memory leak (not by me, I swear!). I've heard that this is a problem with UIImagePickerController but, I'm not sure how to fix it. Here is my implementation of UIImagePickerController.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; // Create the imagePicker
imagePicker.delegate = self;
imagePicker.allowsEditing = YES; // Allow editing of the images
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
Any ideas? I really don't want to sacrifice such a useful feature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SDK 3.2 有同样的泄漏吗?
我在使用 UIImagePickerController 拍摄视频时也遇到了类似的泄漏。
当我发现泄漏在 3.2 中得到修复时,我决定将应用程序的最低操作系统版本设置为 3.2。
关于内存警告,这是可以预料的。相机需要大量内存来完成其工作,并且只是通过发送 didReceiveMemoryWarning 消息向您的应用程序请求尽可能多的内存。
Do you have the same leak with the SDK 3.2?
I had a similar leak when using the UIImagePickerController to take a video.
When I found that the leak was fixed in 3.2, I decided to set the minimum OS version of my application to 3.2.
About the memory warning, it's to be expected. The camera needs a lot of memory to do its job, and is simply requesting as much memory as possible from your app by sending a didReceiveMemoryWarning message.
您需要将图像重新调整为较小的尺寸,例如 320x460。然后就可以成功运行了。
You need to rescale the image to a smaller size, say 320x460. Then it will run successfully.