O'Reilly logo

High Performance iOS Apps by Gaurav Vaish

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Memory Management

iPhone and iPad devices are resource-constrained on memory. An app may be terminated by the operating system if it crosses the established per-process limit.1 As such, successfully managing memory plays a central role in implementing an iOS app.

At WWDC 2011, Apple revealed that about 90% of device crashes happened due to issues pertaining to memory management. And of these, the biggest causes are either bad memory access or memory leaks due to retain cycles.

Unlike the Java runtime (which uses garbage collection), iOS runtimes for Objective-C and Swift use reference counting. The downsides of using reference counting include possible overrelease of memory and cyclic references if the developer is not careful.

As such, it is important to understand how memory is managed in iOS.

In this chapter, we study the following:

  • Memory consumption (i.e., how an app consumes memory)

  • The memory management model (i.e., how the iOS runtime manages memory)

  • Language constructs—we’ll take a look at Objective-C constructs and the available features you can use

  • Best practices for minimizing memory usage without degrading the user experience

Memory Consumption

Memory consumption refers to the RAM that an app consumes.

The iOS virtual memory model does not include swap memory, which means that, unlike with desktop apps, the disk cannot be used to page memory. The end result is that the apps are restricted to available RAM, which is used not only by the app in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required