class Parent {
var child:Child!
init() {}
deinit {
print("Parent's deinit called")
}
}
class Child {
unowned var parent:Parent
init(parent:Parent) {
self.parent = parent
}
deinit {
print("Child's deinit called")
}
}
var parent:Parent? = Parent() // parent refcount: 1
var child:Child? = Child.init(parent: parent!) // parent refcount: 1, child refcount: 1
parent?.child = child // parent refcount: 1, child refcount: 2
/*
do some work with child and parent
*/
parent = nil //parent refcount: 0, child refcount: 1
child = nil //child refcount: 0