Every class instance is eventually destroyed. Swift gives you a way to know exactly when that happens β and the story of how it decides when to pull the trigger is surprisingly interesting.
Here's something you've probably never thought about: what happens to your objects when you're done with them?
With structs, the answer is simple. A struct lives as long as whatever owns it. Create a struct inside a function, the function ends, the struct is gone. Clean, predictable, boring in the best way.
Classes are messier. Remember β when you "copy" a class, you're not copying the data, you're copying a signpost pointing to the data. That means multiple parts of your code might be holding onto a reference to the same class instance. So when does that instance actually get destroyed? When the first reference goes away? The last?
The answer is: the last one. And Swift has a whole system behind the scenes to track it. π₯






