How iOS multitasking really works

There's one bit of iOS misinformation that I keep hearing. Even supposedly authoritative sources such as Apple Geniuses don't seem to get it. It has to do with how multitasking works in iOS.

Here's the statement I keep hearing, and it's wrong:

All those apps in the multitasking bar on your iOS device are currently active and slowing it down, filling the device's memory or using up your battery. To maximise performance and battery life, you should kill them all manually.

The iOS multitasking bar does not contain a list of all running apps. It contains a list of recently used apps. The user never has to manage background tasks on iOS.

Except in a few cases, which I'll explain, the apps that appear in the multitasking bar are not currently running. When you press the home button, iOS will tell the app to quit. In almost all cases, it quits, it stops using processor time (and hence battery), and the memory it was using is eventually recovered, if required.

The five faces of apps

iOS apps can exist in any of five states of execution. These are:

Not Running: The app has been terminated or has not been launched.

Inactive: The app is in the foreground but not receiving events (for example, the user has locked the device with the app active).

Active: The normal state of "in use" for an app.

Background: The app is no longer on-screen but is still executing code.

Suspended: The app is still resident in memory but is not executing code.

Active and Inactive are not relevant to this discussion. Most of the confusion is around what happens as an app goes from Active to Background to Suspended to Not Running.

When you press the home button, the app moves from Active to Background. Most apps usually then go from Background to Suspended in a matter of seconds. (Suspended apps remain in the device's memory. This is so they can resume more quickly when you go back to them. They're not using processor time and they're not sucking battery power.)

You may think that if an app is resident in memory, you might have to remove it manually in order to conserve memory. But you don't: iOS does it for you. If you launch a memory-intensive app such as a game, iOS will start to purge Suspended apps from memory and move them to the Not Running state. That is, they will be completely removed from memory and will launch afresh the next time you tap their icon.

Here's the confusing part: None of these states are reflected in the multitasking bar. That bar always shows a list of recently used apps, regardless of whether they're in the Background, Suspended, or Not Running states. (You may also have noticed that the app that is currently Active does not appear in the multitasking bar.)

Background tasks

Let's take an app that downloads largish files from the Web, such as Instacast, my favorite podcast app. When Instacast is Active, it can start to download new podcasts. By default, if I hit the home button on my iPhone, Instacast would get five seconds to run in the Background state before it would be moved to Suspended. That would interrupt the download of my podcasts, which can take some time. (They're large files.)

But iOS allows apps such as Instacast, which have time-intensive tasks that can run in the background, to ask for a reprieve. The app declares its downloading of podcasts as a "background task." This allows Instacast an extra period of Background running, after I hit the home button, to complete its downloads.

Instacast doesn't have all day. An app gets about ten minutes of Background running time before it is forcibly suspended by iOS. But regardless, this isn't a feature regular users should worry about.

Indefinite background running

So all apps get five seconds of Background running, to clean things up, and some apps (such as Instacast) can request a ten-minute extension. There are, however, a small number of apps that genuinely need to run indefinitely in the background, and iOS allows this.

There are exactly five kinds of apps allowed to run indefinitely in the Background state in iOS 5:

Apps that play audio while in the Background state. A good example is Instacast while it's playing a podcast.

Apps that track your location in the background. For example, you still want voice prompts from your turn-by-turn GPS navigation app, even if another app is Active.

Apps that listen for incoming voice-over-IP (VOIP) calls. If you use Skype on iOS, you can receive incoming Skype calls while the app is in the background.

Newsstand apps that are downloading new content.

Apps that receive continuous updates from an external accessory in the background.

All well-written apps in the above categories should become Suspended when they are no longer performing the task in hand. When Instacast finishes playing a podcast, it should be Suspended. There are some built-in apps that also run continuously in the background on iOS—the most-used one is probably Mail.

As long as these apps are running in the Background state, they will consume memory, CPU time, and power. It's also important to know that an app which is enabled to run indefinitely in the background can do anything that it can do when it's Active. This may include much more than just playing audio or tracking your location. For example, as long as Instacast is playing audio it can also continue to download new episodes in the background.

In general, though, you would know that you were using such apps. The developer has to declare which category of Background running they require, and part of the App Store review process is to check that these declarations are not being abused—although App Store review is never a perfect catch-all.

I said earlier that "the user never has to manage Background tasks on iOS." The only exception to this is when one of these Background-running apps either goes berserk or will not Suspend itself properly. In such a case, you may want to manually kill the app from the Multitasking Bar. This, however, is an unusual situation and not a normal part of being an iOS user. I do think, though, that iOS could do a better job of showing which apps are currently in indefinite Background running, perhaps similarly to the way that apps using Location Services are shown.


Let me wrap this up by giving you a quick summary:

If someone tells you that all the apps in the multitasking bar are running, using up memory or sucking power, they are wrong.

When you hit the home button, an app moves from Active to Background and quickly to the Suspended state, where it no longer uses CPU time or drains power.

An app may request an additional ten minutes of Background running to complete a big task before becoming Suspended.

If memory is becoming scarce, iOS will automatically move Suspended apps into the Not Running state and reclaim their memory.

Five classes of apps—audio, GPS, VOIP, Newsstand and accessory apps—and some built-in apps such as Mail may run indefinitely in the background until they complete their task.

Put simply: You do not have to manage background tasks on iOS. The system handles almost every case for you, and well-written audio, GPS, VOIP, Newsstand, and accessory apps will handle the rest.

This story, "How iOS multitasking really works" was originally published by Macworld.

Insider: How the basic tech behind the Internet works
Join the discussion
Be the first to comment on this article. Our Commenting Policies