Instruments ObjectAlloc: 解释活字节和总字节

我正在使用仪器公司的 ObjectAlloc 工具,试图了解我的应用程序(iPhone)正在执行的内存操作,以及执行操作的时间和地点。

我真的很想对这些统计数字做一个基本的解释:

  • 活字节
  • # 活着
  • # 转瞬即逝
  • 总字节数

当我试图计算我的应用程序使用了多少内存时,我应该查看 Live 字节还是总体字节?这包括内存泄漏吗?什么是临时对象?

谢谢

23672 次浏览

ObjectAlloc tracks all memory allocation and deallocation over the time your program is running.

The Living bytes, or Net bytes is how much memory your application is using at the time you select in the timeline. That will include leaked memory, since leaked memory is never deallocated.

#Living is how many allocations of a certain size/object type happened (and are still allocated). This is very useful when looking for leaks.

For example, if you repetitively perform an action (like coming in an out of a modal view controller), and you see that #Living of an object grows by the same amount each time, then you're probably leaking those objects. You can then confirm by drilling down and seeing the exact line of code that is allocating the objects, and even see the time index each one was created.

Overall bytes includes memory that has been released. It's useful to track that number for performance optimization purposes, but not if you're just trying to see your current memory footprint or look for leaks.

Stats explanation from apple docs. Link to the document

enter image description here

enter image description here