在CocoaTouch(iPhone OS)中如何找到/消除Instruments Leak工具找不到的泄漏? [英] In CocoaTouch (iPhone OS) how do I find/eliminate leaks that the Instruments Leak tool doesn't find?

查看:161
本文介绍了在CocoaTouch(iPhone OS)中如何找到/消除Instruments Leak工具找不到的泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,在模拟器中运行伟大。它通过摆脱一切不是绝对必要的内存警告响应很好。当我在设备上运行它,它运行良好。但在一定量的使用后它崩溃与错误代码101 - 从我可以告诉,是操作系统杀死它由于内存使用。我可以看到内存警告(我记录它),我的应用程序响应,但后不久死亡。

I have an iPhone app that is running great in the simulator. It responds well to the memory warnings by getting rid of everything that is not absolutely essential. When I run it on the device, it runs well. But after a certain amount of usage it crashes with error code 101 - which, from what I can tell, is the OS killing it due to memory usage. I can see the memory warning (I'm logging it), and my app responds to it, but dies shortly thereafter.

如果我在Instruments(无论是在设备上还是在sim中)查看应用程序,它没有发现任何泄漏。此外,净内存使用量在600-700k字节的范围内。从我的应用程序的不同视图转换增加了内存使用(如预期),但是当视图和控制器被释放和释放,内存使用从来没有如此低。然而,添加通常仅在1000-2000字节的范围内。所以,虽然泄漏显示我没有泄漏,我怀疑在某个地方有一个问题。我还查看了我分配的所有对象,并且所有这些对象似乎都按预期回收。我看到的增加的唯一的对象是GeneralBlock-N(其中N是一些数字)

If I look at the app in Instruments (either on the device or in sim), it doesn't find any leaks. In addition, the net memory usage is in the range of 600-700k bytes. Transitioning from the different views of my app increases memory usage (as expected), but when the views and controllers are released and dealloc'd, the memory usage never quite goes as low as it was. However, the addition is usually only something in the range of 1000-2000 bytes. So while Leaks shows me no leaks, I suspect there is an issue somewhere. I've also looked at all of the objects I'm allocating, and all of them seem to be reclaimed as expected. The only objects I see that keep increasing are GeneralBlock-N (where N is some number)

我应该不注意仪器净使用数字?尝试诊断问题的后续步骤是什么?

Should I not pay any attention to Instruments net usage figure? What would be the next steps in trying to diagnose the issue?

ADDED:我没有对malloc()或任何CoreFoundation库的任何调用,它将返回我负责的缓冲区。我所做的唯一非Obj-C调用是NSLog的日志语句。

ADDED: I'm not making any calls to malloc() or any CoreFoundation libraries that would return a buffer that I'm responsible for. The only non-Obj-C calls I'm making are logging statements to NSLog.

推荐答案

(感谢一些出色的答案和评论):

Here's a summary of what I've learned (thanks to some excellent answers and comments):


  • 对象分配与内存使用不同。对于我的问题关于ObjectAlloc的净字节元素的答案是,你不应该注意它 - 至少不是当确定与您使用的内存量的问题或什么导致它崩溃。它不会反映您的应用程序的真实内存使用情况。

  • 我惊讶的猜测是ObjectAlloc只显示直接对象本身占用的内存。因此,如果你有一个UIImageView,它只需要少量的字节来存储各种属性,但它可能指向内存中的一个图像占用一大堆空间。因此,查看ObjectAlloc仅仅有助于确保不会创建和保持对象,它不会让你知道你使用了多少内存或在崩溃之前可以使用多少内存。

  • MemoryMonitor将为您提供总内存使用率。您可以通过使用仪器窗口右下角的搜索工具限制它只查看应用的使用情况。

  • ObjectAlloc和内存监视器(以及漏洞工具)都是插件为仪器 - 只是为了对其他人不明显。您可以通过执行Run - > Start with Performance Tool从XCode中启动仪器。进入乐器之后,您可以打开库并添加新的插件来监控效果的不同方面。

  • Object Allocation is NOT the same as Memory usage. The answer to my question about ObjectAlloc's net bytes element is that you shouldn't be paying attention to it - at least not when determining issues with the amount of memory you are using or whats causing it to crash. It doesn't reflect the true memory usage of your application.
  • My amatuerish guess is that ObjectAlloc only shows you the memory taken up by the direct object itself. So if you have an UIImageView, it takes up just a handful of bytes to store the various properties, but it might be pointing to an image in memory taking up a bunch of space. Therefore, looking at ObjectAlloc is helpful only in making sure you're not creating and keeping objects around, it won't give you an idea of how much memory you're using or how much you can use before crashing.
  • MemoryMonitor will give you the total memory usage. You can constrain it to viewing only your app's usage by using the search tool in the bottom right of the Instruments window.
  • Both ObjectAlloc and Memory Monitor (as well as the Leaks tool) are plugins for Instruments - just in case thats not obvious to someone else. You can launch Instruments from within XCode by doing Run -> Start with Performance Tool. Once inside of Instruments, you can open the Library and add new plugins to monitor different aspects of performance.

这篇关于在CocoaTouch(iPhone OS)中如何找到/消除Instruments Leak工具找不到的泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆