Weak references for delegate, protocol & block

I know we have to use weak reference for delegate, datasource and while accesing variables in the block to avoid retain cycle. Can anyone explain why object will be retained if we use strong reference

Replies

Look at Apple Inc. « The Swift Programming Language (Swift 4). » iBooks..

ARC does not dispose of an instance if some other holds a strong reference on it. If weak, it can dispose of it.


« Weak References

A weak reference is a reference that does not keep a strong hold on the instance it refers to, and so does not stop ARC from disposing of the referenced instance. This behavior prevents the reference from becoming part of a strong reference cycle. You indicate a weak reference by placing the weak keyword before a property or variable declaration.



Because a weak reference does not keep a strong hold on the instance it refers to, it’s possible for that instance to be deallocated while the weak reference is still referring to it. Therefore, ARC automatically sets a weak reference to nil when the instance that it refers to is deallocated. And, because weak references need to allow their value to be changed to nil at runtime, they are always declared as variables, rather than constants, of an optional type. »


Apple Inc. « The Swift Programming Language (Swift 4). » iBooks.

Did that answer your question ?