class A {
var a: Int
var b: String
weak var s: CustomType?
init(a:Int, b: String, s: CustomType?) {
....
}
func methods() {
}
}
class B {
....
var a: A
init(a: A) {
self.a = a
}
}
class C {
var b: B
init(s: CustomType?) {
a = A(a:Int, b: String, s: CustomType?)
b = B(a: A)
}
}
// main
let s : CustomType? = CustomType() //
let c = C(s)
...
...
// finish
在这种情况下,我是否需要担心
s
或 class A
的对象 a
的垃圾收集?
或者 Swift 的垃圾收集器会自动处理它? (或者a
可以变得悬空???)