快速垃圾收集将如何处理这种情况?

问题描述 投票:0回答:0
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
可以变得悬空???)

class object memory memory-management memory-leaks
© www.soinside.com 2019 - 2024. All rights reserved.