infer icon indicating copy to clipboard operation
infer copied to clipboard

Clarification regarding "Retain Cycle" in the documentation.

Open RameshAran opened this issue 10 years ago • 1 comments

I found this from the following documentation. http://fbinfer.com/docs/infer-bug-types.html#RETAIN_CYCLE

The Retain Cycle is described as follows.

@class Child; @interface Parent : NSObject { Child *child; } @end @interface Child : NSObject { __weak Parent *parent; } @end

But I think, this is valid if "Child" is a subclass of "Parent". Here both Child and Parent are inherited from NSObject class and hence are independent. I think the documentation should be corrected as follows.

@class Child; @interface Parent : NSObject { Child *child; } @end @interface Child : Parent { __weak Parent *parent; } @end

Please correct me if I am wrong.

RameshAran avatar Jan 24 '16 06:01 RameshAran

No, Child and Parent don't need to be inherited from each other for there to be a retain cycle. If parent has a property child that is strong, and Child has a strong property parent, then you will get a cycle parent -> child -> parent, that cannot be deallocated.

dulmarod avatar Jan 25 '16 11:01 dulmarod