O'Reilly logo

Learning Swift by Andrew J Wagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Automatic reference counting

Now that we understand the different ways in which data is represented in Swift, we can look at how to manage memory better. Every instance we create takes up memory. Naturally, it wouldn't make sense to keep all data around forever. Swift needs to be able to free up memory that can be used for other purposes once our program doesn't need it anymore. This is the key to managing memory in our apps. We need to make sure that Swift frees up all the memory that we no longer need as soon as possible.

The way that Swift knows it can free up memory is when the code no longer has access to an instance. If there is no longer any variable or constant referencing an instance, it can be repurposed for another instance. This is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required