I incurred a small problem to solve retain cycle in Swift 4. (the same code works fine in swift 3) what do i miss please?
class User {
weak var device:Device?
init() {
print("User allocated")
}
deinit {
print("User deallocated")
}
}
class Device {
weak var user:User?
init() {
print("Device allocated")
}
deinit {
print("Device deallocated")
}
}
var user:User! = User();
var device:Device! = Device()
user.device = device;
device.user = user
user = nil;
device = nil
the output is :
User allocated
Device allocated
without no one of deallocated message.
Why? Thanks for your help.