Chapter 4: delegate pattern without retain cycle explanation?

Why don’t you explain that a delegate property needs to be weak to prevent retain cycles?

also, in the example code its not weak which causes a retain cycle

2 Likes

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

@tomereven Thanks very much for your question!

In the first paragraph of the chapter, it states:

An object needing a delegate, also known as the delegating object. It’s the object that has a delegate. The delegate is usually held as a weak property to avoid a retain cycle where the delegating object retains the delegate, which retains the delegating object.

So in fairness, it is mentioned in the chapter, however, to your point, I don’t see the delegate properties in the chapter being designated as weak. This may be an oversight on our part, but I will try to get one of the authors to perhaps clarify this.

Thanks very much for bringing this to our attention!

@syedfa Thanks for the reply here!

A couple additional notes:

We do mention that delegates can be used to break retain cycles, but it’s a fair point that more emphasis could be placed on this.

You’re right. This seems to be an error, and it should indeed be weak.

I’ll get these both included in the next version of the book and released soon.

Thanks for the feedback. :smile: