Retain Cycles: Why is that such a bad thing?

前端 未结 4 811
孤街浪徒
孤街浪徒 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:53

    The problem is this: A points to and retains B, and B points to and retains A. When there are no other references to A or B, there will be no way to release them, because you app doesn't have any references to them at that point. This is called a reference cycle, and it a type of memory leak common in any reference counted system. The way this is solved in most high level languages is by using garbage collection rather than reference counting.

提交回复
热议问题