How to debug memory leaks when Leaks instrument does not show them?

前端 未结 2 1811
我寻月下人不归
我寻月下人不归 2020-11-22 07:58

I have an iOS app written in Swift that is leaking memory - in certain situation some objects should be released but they are not. I have learnt about the issue by simply ad

2条回答
  •  粉色の甜心
    2020-11-22 08:24

    Use instruments to check for leaks and memory loss due to retained but not leaked memory. The latter is unused memory that is still pointed to. Use Mark Generation (Heapshot) in the Allocations instrument on Instruments.

    For HowTo use Heapshot to find memory creap, see: bbum blog

    Basically the method is to run Instruments allocate tool, take a heapshot, run an iteration of your code and take another heapshot repeating 3 or 4 times. This will indicate memory that is allocated and not released during the iterations.

    To figure out the results disclose to see the individual allocations.

    If you need to see where retains, releases and autoreleases occur for an object use instruments:

    Run in instruments, in Allocations set "Record reference counts" on (For Xcode 5 and lower you have to stop recording to set the option). Cause the app to run, stop recording, drill down and you will be able to see where all retains, releases and autoreleases occurred.

提交回复
热议问题