Book Image

Application Development with Swift

By : Hossam Ghareeb
Book Image

Application Development with Swift

By: Hossam Ghareeb

Overview of this book

Table of Contents (14 chapters)

Memory management


Memory management is one of the most important topics that every developer should be aware of when making their app very responsive and efficient. Swift uses Automatic Reference Counting (ARC) to manage memory. In ARC, freeing up memory and managing it is done automatically when instances are no longer needed. Although ARC does most of the work in memory management, you have to care about the relations between classes to avoid memory leaks.

In memory, each object has a reference counting, and when it reaches zero, this object will be deallocated from the memory. In Swift, we have two types of references: strong and weak. The strong references retain the object and increment its reference counting by 1; the weak references don't increment the reference counting. In Swift, when you assign a class reference to a variable, constant, or a property, it makes a strong reference to it and it will remain in the memory as long as you use it. Take care while using relations between...