How can identify strong reference cycles in Swift?

前端 未结 5 1952
无人及你
无人及你 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 07:53

    You can add deinit functions to your classes that will get called when your objects are deallocated.

    If deinit isn't getting called, while your app is running, you can press the Debug Memory Graph button (circled below) and inspect what has a reference to what.

    Use the dropdown menus at the top of the middle pane to toggle between classes and instances of classes.

    If something is getting allocated over and over again without getting released you should see multiple instances, and you should be able to see via the directional graph if one of its children is holding a strong reference to its parent.

提交回复
热议问题