Ambiguities in using Instruments for iOS Development

后端 未结 2 1612
野趣味
野趣味 2021-01-05 11:22

I am Profiling an Application with Instruments. The profiling is done using Allocations Tool in two ways:

  1. By choosing Directly the Allocations when I run the A
2条回答
  •  广开言路
    2021-01-05 11:58

    In the first case, you are only tracking live allocations because the "Leaks" template configures the Allocations instrument that way. In the second, you are tracking both live and deallocated allocations. (As CocoaFu said).

    Both are useful, but for slightly different reasons.

    Only tracking live allocations (in combination with Heapshot Analysis, typically), is a great way to analyze permanent heap growth in your application. Once you know what is sticking around forever, you can figure out why and see if there are ways to optimize it away.

    Tracking all allocations, alive and dead, is a very effective means of tracking allocation bandwidth. You can sort by overall bytes and start with the largest #. Have a look at all the points of allocation (click the little arrow next to the label in the Category of the selected row), and see where all the allocations are coming from.

    For example, your graph shows that there are 1.27MB of 14 byte allocations -- 9218 allocations -- over that period of time. All have been free()d [good!], but that still represents a bunch of work to allocate, fill with data (presumably), and free each one of those. It may be a problem, maybe not.

    (To put this in perspective, I used this technique to optimize an application. By merely focusing on reducing the # of transient -- short lived -- allocations, I was able to make the primary algorithms of the application 5x faster and reduce memory use by 85%. Turns out the app was copying strings many, many, times.)


    Not sure why your app crashed as you described. Since it is a memory warning, you should see what is most frequently allocated.

    Keep in mind that if you have zombie detection enabled, that takes a lot of additional memory.

提交回复
热议问题