I was exploring memory management concept and found
deinit
method is not calling in Xcode 10 beta 6 playground. Initially I thought may be some pro
This issue seems to still be present in Xcode 10.0 (10A255). I have playground with the following code:
class Person {
var name: String
func buy(car: Car) {
car.owner = self
}
init(name: String) {
self.name = name
print("Person \(name) is initalized")
}
deinit {
print("Person \(name) is being deinitialized")
}
}
class Car {
let model: String
weak var owner: Person?
init(model: String) {
self.model = model
print("Car \(model) is initialized")
}
deinit {
print("Car \(model) is being deinitialized")
}
}
print("===== before do =====")
do {
print(" ---- do begin -----")
let johnny = Person(name: "John")
let porsche = Car(model: "Carrera4")
johnny.buy(car: porsche)
print(" ---- do end -----")
}
print("===== after do =====")
In Xcode 9.4.1 both Car's and Person's deinit are executed, but in Xcode 10.0 (10A255) the Person's deinit method is not executed.
The same code inside a test macOS project works as expected (both deinit executed) in Xcode 9.4.1 as well as Xcode 10.0 (10A255)