[swift-evolution] Type based reference cycle detection

Daniel Duan daniel at duan.org
Sun Feb 28 12:42:05 CST 2016


> On Feb 28, 2016, at 10:26 AM, Darko Damjanovic <darkodamjanovic at me.com> wrote:
> 
> 
>>    class A { let myP: P?  }
>> 
>>    class P { let myX: AnyObject?  }
>> 
>> Should this code generate a cycle warning? What if myP's type is
>> GreatGreatGreatGrandParentOfP? Should any two class with a strong reference to
>> AnyObject generate a warning?
> 
> Of course not. Extending the attempt to solve reference cycles in all special cases like inherited types, protocols, generics (is an Array<P> a P?) etc... would lead immediately to the thought "this is not possible to solve in a clean way“. And I think it would be true.
> 
> In my experience in app development almost 100% of all reference cycles where caused by the most simple form. And I don't have hard statistical data about it, just my own experience. But let's assume that 80% of all strong reference cycles during app development are in this simple form. Or just 50%. Wouldn't it still be great to have a warning in 50% of all possible strong reference cycles even if not all other cases are considered?
> 
> - Darko
> 
> 


Note I agree that a warning about retain cycle is a good idea. Otherwise
I would not bring up how to implement it at all.  (I happened to have
implemented the cycle detection for value types in swiftc. During that process
I thought about this very issue, a lot.)

The key phrase here is “simple form”. We need to translate this into code at
some point, no?




More information about the swift-evolution mailing list