参照カウント
例4
class Hoge {
private var closure: (() -> Void)?
private var count = 0
init() {
closure = createClosure()
}
func createClosure() -> (()-> Void) {
return {
self.count += 1
}
}
}
var h: Hoge? = Hoge() // Hoge
の参照カウント2 , closure
の参照カウント1
h = nil // Hoge
の参照カウント1
hoge
と closure
で循環参照が起きている 12