Automatic Reference Counting (ARC): How Swift’s Memory Management Works

Understand Swift’s ARC Concept in Just a Few Minutes

Arc Sosangyo
5 min readOct 27, 2024
Photo by Kowon vn on Unsplash

Ever wonder how your app manages to run smoothly without turning into a memory-hogging monster? It all boils down to how your code cleans up after itself. In some languages, garbage collection (GC) is like the friend who promises to tidy up but only does it after your place looks like a hurricane hit. Meanwhile, Swift’s Automatic Reference Counting (ARC) is that meticulous roommate who picks up the coffee cup the moment you put it down.

This article is part of my Swift Programming Tutorial series.

But what exactly is ARC, and how is it different from the garbage collection you’ve heard about in other programming languages?

Imagine this scenario:

You’re hosting a party (your Swift program), and every guest at the party is an object in memory. You only have so many chairs (memory space) for people to sit in. Now, you’re super hospitable, so whenever someone (a part of your code) comes over to talk to a guest (object), they get a chair. But when nobody’s talking to them anymore, they leave the party (bye-bye, memory!) — this is ARC at work.

--

--

Arc Sosangyo

Arc is an iOS Dev and app publisher, a former IT manager who transitioned to iOS engineering, and a big fan of AI, coding, science, history, and philosophy.