24 Memory Management and ARC

All computer programs use memory. Most computer programs use memory dynamically: as a program runs, it allocates and deallocates memory as needed. Swift’s stance on memory management is relatively unique. Most memory issues are handled for you automatically, but Swift does not use a garbage collector (a common tool for automatic memory management in programming languages). Instead, Swift uses a system of reference counting. In this chapter, you will investigate how that system works and learn what you need to be aware of to avoid memory leaks.

Memory Allocation

The memory allocation and management for value types – enumerations and structures – is very simple. When you create a new instance ...

Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.