Tips for finding and debugging abandoned memory and heap growth

前端 未结 2 849
无人共我
无人共我 2020-12-28 10:21

I recently watched one of the WWDC 2010 videos: Session 311 - Advanced Memory Analysis with Instruments. The link is here.

There is an interesting example in the vid

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 11:06

    To summarize bbum's excellent blog post:

    1. Profile your app using Instruments
    2. Use the Allocations template
    3. When the app isn't running, click the little i next to the Allocations track header and check Record reference counts; this will let you know where the items are being retained, not just where they are allocated.
    4. Run your app, do something, then return to a default state. For example, open a new document window, then close it.
    5. Click the "Mark Heap" button in Instruments.
    6. Repeat steps 4 and 5 several times.

    When you review the allocations in Instruments, you can click the right-arrow button to see a history of events for that instance, including all places it was allocated, retained, released, and autoreleased.

提交回复
热议问题