Skip to content

Instantly share code, notes, and snippets.

@longvudai
Last active March 18, 2020 18:10
Show Gist options
  • Save longvudai/acb9520e65013c054968f793b5825060 to your computer and use it in GitHub Desktop.
Save longvudai/acb9520e65013c054968f793b5825060 to your computer and use it in GitHub Desktop.
ARC-medium
class Person {
let name: String
init(name: String) {
self.name = name
print("\(name) is being initialized")
}
deinit {
print("\(name) is being deinitialized")
}
}
var reference1 = Person(name: "John Appleseed")
// output: "John Appleseed is being initialized"
var reference2: Person?
var reference3: Person?
reference2 = reference1
reference3 = reference1
reference1 = nil // reference counts = 2
reference2 = nil // reference counts = 1
reference3 = nil // reference counts = 0
// output: "John Appleseed is being deinitialized"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment