I am not getting the last line of this code as I am not 100% sure why the reference count becomes 0. I have a guess but I can’t confirm it. Guess: Reference became 0 because variable “john” was reassigned therefore the reference link had to de-reference before pointing to a new instance. But the confusing part is, it has the same firstName and lastName, does that mean it will create a new instance and point to it instead?
Code from Book:
// Person object has a reference count of 1 (john variable)
var john = Person(firstName: “Johnny”, lastName: “Appleseed”)
// Reference count 2 (john, anotherJohn)
var anotherJohn: Person? = john
// Reference count 6 (john, anotherJohn, 4 references)
// The same reference is inside both john and anotherJohn
var lotsaJohns = [john, john, anotherJohn, john]
// Reference count 5 (john, 4 references in lotsaJohns)
anotherJohn = nil
// Reference count 1 (john)
lotsaJohns = [ ]
// Reference count 0!
john = Person(firstName: “Johnny”, lastName: “Appleseed”)