Retain Cycles: Why is that such a bad thing?

前端 未结 4 812
孤街浪徒
孤街浪徒 2020-12-03 15:23

There are two Objects A and B. A creates B and retains it. B has an instance variable that points to A, retaining it. So both retain eachother. Some people say, that this st

4条回答
  •  春和景丽
    2020-12-03 15:42

    The way to break a retain loop is to have a separate "close" method.

    i.e.

    A retains B
    B retains A
    

    when you're done, call a method (I'll call it "close") on A where A releases B. You can then release A and the whole loop will release (assuming there are no retains elsewhere).

提交回复
热议问题