Why use weak pointer for delegation?

The reason that objects weakly retain their delegates is to avoid retain cycles. Imagine the following scenario: object a creates b and retains it, then sets itself as b‘s delegate. a is released by its owner, leaving a retain cycle containing a and b. This is actually a very common scenario. Consider a view controller that owns a view and acts as that view’s delegate. In this case, the view should not retain the controller—as a mater of proper MVC architecture and to prevent retain cycles.

Leave a Comment