简体   繁体   中英

why it is recommended to use the _weak reference with delegates

Hi every one whether some one will elaborate me that why it is recommended to use the _weak reference for delegates and not the strong reference? though we can also use the strong reference for delegates. Some one will please tell me with the better and descriptive example with simple way that in which situations should we use the strong reference and in which situations should we use the _weak reference for the delegates.

I went through one of the related question on stack overflow

Is it ever Ok to have a 'strong' reference for a delegate?

but it did not clear my concept properly.

Any help will be highly appreciated !!

Thanks.

Using __strong on delegate is very easy to create retain cycle:

say A has a strong reference to B, and some object set A as a delegate of B, if the delegate is strongly referenced, then, a retain cycle is formed.

Yes, It's east to creat a retain cycle while using __strong on delegate.

Addtionally, in ARC, we using weak on delegate,while the object using the delegate is released,the delegate will be nil automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM