EDU*_*sta 9 objective-c uiimagepickercontroller ios7
我有一个UIViewController,它具有:
@property UIImagePickerController* mainPicker;
Run Code Online (Sandbox Code Playgroud)
并使用一个按钮,我正在呈现mainPicker,如:
- (IBAction)takePhoto:(UIButton *)sender
{
// Take a photo.
if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// No camera is available, show an alert.
UIAlertView* newAlert = [[UIAlertView alloc] initWithTitle:@"Warning"
message:@"Camera is not available."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[newAlert show];
return;
}
if(mainPicker == nil)
{
mainPicker = [[UIImagePickerController alloc]init];
mainPicker.delegate = self;
mainPicker.allowsEditing = YES; //I've tried without this line, didn't affect at all.
mainPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:mainPicker animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
第一个问题是;
Snapshotting a view that has not been rendered results in an empty snapshot.
Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Run Code Online (Sandbox Code Playgroud)
此外,每当显示该视图控制器时,至少有两个内存警告.
我拍照后,情况变得更糟.它实际上是垃圾邮件"收到内存警告".
这是一个仪器截图,希望它会有所帮助.

开始时内存大约为4 MB.拍照后,最高可达10 MB.在解雇时,我正在保存UIImage,因此解雇后将近30 MB.(内存的峰值可能是由writeToFile引起的:而且,泄漏只有大约600字节).
目前,我正在使用iOS 7测试iPhone 5S.
我已经尝试过启用僵尸,一段时间后调度选择器,允许/禁止编辑等等.它们都没有工作.此外,我不是在加载视图控制器后立即尝试显示选择器视图.
另外注意,我已经使用了答案中的函数,这是日志;
Memory used 9588.7 (+9589), free 32063.5 kb
Memory used 10281.0 ( +692), free 18448.4 kb
Run Code Online (Sandbox Code Playgroud)
在设备中看到32 MB的可用内存是不是有点奇怪,而Instruments正在讲另一个故事?
以下是一些可以帮助您解决问题的解释。
首先,Zombies 诊断工具旨在调试正在访问已释放内存的崩溃。这似乎不是您的问题,因此僵尸工具对于您的这个特定问题将毫无用处。
其次,您向我们提供的屏幕截图显示了 Leaks 工具。您在该列表中看到的元素是您的程序已分配并忘记但未事先释放它们的对象。这意味着您没有任何指向 Instruments 知道的内存的剩余指针。修复这些泄漏是修复内存警告的第一步。
第三,修复泄漏可能不足以解决内存警告问题。这些警告表明您使用了过多的内存,不符合 iOS 的喜好。考虑到您的泄漏仅占 600 字节,问题似乎是您废弃的内存。废弃的内存是您已分配的内存,您仍然对其具有实时引用,即使它们可能永远不会被您的应用程序再次使用。
为了帮助您解决问题,这里有一些使用 Instruments 修复内存泄漏和废弃内存的相关文档:
https://developer.apple.com/library/mac/recipes/Instruments_help_articles/FindingMemoryLeaksinYourApp/FindingMemoryLeaksinYourApp.html# //apple_ref/doc/uid/TP40012965-CH32-SW1
https://developer.apple.com/library/mac/recipes/Instruments_help_articles/FindingAbandonedMemory/FindingAbandonedMemory.html
另外,这里有一篇关于废弃内存的有用博客文章: http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-寻找不良内存增长/
| 归档时间: |
|
| 查看次数: |
635 次 |
| 最近记录: |