Skip to Content
iOS 10 Programming Fundamentals with Swift
book

iOS 10 Programming Fundamentals with Swift

by Matt Neuburg
October 2016
Beginner content levelBeginner
400 pages
17h 20m
English
O'Reilly Media, Inc.
Content preview from iOS 10 Programming Fundamentals with Swift

Chapter 12. Memory Management

Class instances, both in Swift and in Objective-C, are reference types (see “Value Types and Reference Types”). Behind the scenes, Swift and Objective-C memory management for reference types works essentially the same way. Such memory management, as I pointed out in Chapter 5, can be a tricky business.

Fortunately, Swift uses ARC (automatic reference counting), so that you don’t have to manage the memory for every reference type object explicitly and individually, as was once necessary in Objective-C. Thanks to ARC, you are far less likely to make a memory management mistake, and more of your time is liberated to concentrate on what your app actually does instead of dealing with memory management concerns.

But even with ARC it is still possible to make a memory management mistake, or to be caught unawares by Cocoa’s memory management behavior. A memory management mistake can lead to runaway excessive memory usage, crashes, or mysterious misbehavior of your app, and even in Swift it is possible to make such a mistake. Cocoa memory management can be surprising in individual cases, and you need to understand, and prepare for, what Cocoa is going to do.

Principles of Cocoa Memory Management

The reason why reference type memory must be managed at all is that references to reference type objects are merely pointers. The real object pointed to occupies a hunk of memory that must be explicitly set aside when the object is brought into existence and that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

iOS 11 Programming Fundamentals with Swift

iOS 11 Programming Fundamentals with Swift

Matt Neuburg

Publisher Resources

ISBN: 9781491970065Errata Page