Created
March 28, 2017 23:39
-
-
Save jamesrochabrun/f4214372a8ee2549ebc3422ab44799b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
let name: String | |
var apartment: Apartment? | |
init(name: String) { | |
self.name = name | |
} | |
deinit { | |
print("\(name) is being deinitialized, memory deallocated") | |
} | |
} | |
class Apartment { | |
let unit: String | |
weak var tenant : Person? | |
init(unit:String) { | |
self.unit = unit | |
} | |
deinit { | |
print("Apartment \(unit) is being deinitialized, memory deallocated") | |
} | |
} | |
var person: Person? = Person(name: "Sasha") | |
var apartment: Apartment? = Apartment(unit: "4f") | |
person?.apartment = apartment | |
apartment?.tenant = person | |
person = nil | |
// prints "Sasha is being deinitialized, memory deallocated" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment