Automatic Reference Counting

Now is a good time to talk about Automatic Reference Counting, otherwise known as ARC. If you are an Objective-C programmer, then you know all about ARC. If you were one of the first iPhone programmers, you know that you used to have to do your own reference counting. You will be happy to know that for the most part, you can let Swift worry about the management of memory.

When you create instances of classes, those classes exist by reference. When those instances are no longer needed, Swift cleans them up for you.

ARC works by keeping track of the instances of classes that you create and where those instances are referenced. Every time you create a new instance of a class, ARC finds some free memory available where ...

Get Learning Swift™ Programming 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.