How can identify strong reference cycles in Swift?

前端 未结 5 1906
无人及你
无人及你 2021-01-30 07:09

Is there a tool or method to locate strong references cycles in my SWIFT code?

A strong reference cycle is when two instances of classes reference each other without

5条回答
  •  孤街浪徒
    2021-01-30 08:02

    Use instruments to check for leaks and memory loss. 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.

提交回复
热议问题