Why are Objective-C delegates usually given the property assign instead of retain?

The reason that you avoid retaining delegates is that you need to avoid a retain cycle:

A creates B
A sets itself as B’s delegate

A is released by its owner

If B had retained A, A wouldn’t be released, as B owns A, thus A’s dealloc would never get called, causing both A and B to leak.

You shouldn’t worry about A going away because it owns B and thus gets rid of it in dealloc.

Leave a Comment