Using heap shot analysis shows memory addresses, but not lines of code. How do I determine what is causing the heap to grow?

后端 未结 2 675
一整个雨季
一整个雨季 2021-01-07 01:49

I\'m nearly finished with my app and I\'m using Instruments to optimize performance before I submit to the app store. I noticed that whenever I execute a particular action (

相关标签:
2条回答
  • 2021-01-07 02:09

    Start with bbum's tutorial: When is a Leak not a Leak?

    The short answer is that there is no tool that is going to tell you the exact line of code that causes a leak. The system does not know where you made your mistake. It knows when you allocated memory, and it knows that memory hasn't been released, but it has no way to know whether you meant to release the memory or not. It especially does not know when you should have released the memory because it has no way to know why you allocated it in the first place.

    Using heap shots, you can discover what the extra objects are, and from there you can audit how you use those objects.

    0 讨论(0)
  • 2021-01-07 02:29

    A couple of thoughts:

    1. In the heap shot, don't forget to show the extended detail (+E or select "Extended Detail" from the "View" menu) in the rightmost panel of Instruments.

      When viewing extended detail, it will show you a stack trace, and you can double-click on your method name there (which will be in black rather than light gray) and you'll be taken to the line that generated the allocation (which obviously isn't necessary the root problem, but it will show you where the object was originally allocated, which is a place to start).

      view extended detail in heapshot analysis

    2. Having said that, I generally focus on the standard Allocations tool first. I'll option-drag in the allocations instrument timeline at the top to highlight allocations within this time window of execution, I'll then select "Call Tree", and to focus on just my code, I'll check the "Invert Call Tree" and "Hide System Libraries" boxes:

      option drag in allocations tool

      For me, I find that's a more efficient way of identifying my allocations that took place within that window of time, without sifting through system allocations.

    3. Do not forget to run your code through the static analyzer in Xcode (shift++B or choose "Analyze" on the "Product" menu). You should get a clean bill of health there before you even start running your app through Instruments.

    0 讨论(0)
提交回复
热议问题