Understanding retain cycle in depth

Tariq picture Tariq · Nov 10, 2013 · Viewed 39.1k times · Source

Lets say we have three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent.

What will happen in this case ?

Answer

rmaddy picture rmaddy · Nov 10, 2013

Unless there is some other reference to the parent or child, they both become orphaned. But the retain cycle between the parent and child prevent either from being released and they become wasted memory.

A child should never retain a parent. If anything, use a weak reference in the child to maintain a reference to the parent.