I am interested in retaining cycles. Let assume we have two views, A and his subview B.
I know that if B has a (custom) delegate defined as
class B: UIView {
var delegate : CustomDelegate?
}
and I set inside A :
b.delegate = self
This create retain cycle, because B has strong reference to A and A has strong reference to be, so neither could be freed.
Question :
What if I have object inside A and I want to pass it to the B object.
class B: UIView {
var object : SomeObject?
}
and inside A :
b.object = self.object
Is this a retaining cycles too? I can't figure this out.
When object (in A) is created it's reference is 1. When it is passed to the B it's reference is 2. But when A try to deallocate itself : When deallocate object in A it reduce reference to 1 and when he try to deallocate B the object reference should go to 0. Is this mean that there is no retaining cycles? Or did B holds indirect reference to A trough object?
Second question :
What could I lose if all object inside B would be weak references? Or better witch object need to be weak?