Memory Management
For many years, the primary languages that I used were C and C-based object-oriented languages. These languages required a good handle on managing memory and knowing when to release memory. Luckily, modern languages like Swift take care of managing memory for us. However, it is a good idea to understand how this memory management works so we can avoid the pitfalls that cause this memory management to fail.
In this chapter, we will learn:
- How ARC works
- What a strong reference cycle is
- How to use weak and unowned references to prevent strong reference cycles
As we saw in Chapter 17, Custom Value Types, structures are value types and classes are reference types. What this means is that when we pass an instance of a structure within our application, such as a parameter of a method, we create a new instance of the structure in the memory. This new instance of the structure is only valid while the application is in the scope where...