[swift-evolution] Type based reference cycle detection
Daniel Duan
daniel at duan.org
Sun Feb 28 11:58:04 CST 2016
Darko Damjanovic via swift-evolution <swift-evolution at ...> writes:
> most basic form:
>
> class A {
> let myB: B?
> }
>
> class B {
> let myA: A?
> }
>
One workaround available today is the replace classes with structs. Due to
struct's value semantics, the complier have to (and does) ban the relationship
in this example. (I understand this is not very practical when it comes to
UIKit components).
For reference types such as class, a warning about retain cycle seems
reasonable. But there should also be a way to silence the warning. I can see
deliberate use cases for this example, such as abandoning weak references to
avoid performance hit.
Implementing this feature would be…interesting. Example:
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? We have to answer these questions before even
talking about how to implement it.
More information about the swift-evolution
mailing list