Sunday, June 17, 2012

Should I Close "Background" Apps On My iOS Device?


When people get a new iPhone, iPad or iPod touch and discover how the multitasking bar works, they get this nagging feeling in their head about the apps still 'running' in the background draining their battery. I was one of them, until I learned about how iOS manages memory and background apps. I have seen countless people in public opening the multitasking tray and closing separately every single app that is visible in it.


This post is somewhere between a guide, explainer, myth-buster and a rant. Let me tell you something: The apps open in the background mean almost nothing and do not need closing. Here's why...
How iOS manages memory
iOS manages memory really well. It prioritizes the app that is currently running over anything else. When it needs more memory for the current app, it starts to close down apps that are running in the background. There are five app states in iOS: Not running, Active, Inactive, Background and Suspended. Each of these is explained in Table 3-1 here.

In this case, we are talking about Background and Suspended apps.

Some apps, such as Skype and Internet radio apps (Songza, Pandora) remain in Background state when you press the Home Button. They consume power and CPU cycles as they work in the background.

Most properly designed apps should stay in the Suspended state when they are closed using the Home Button. In this state, apps don't consume power or CPU cycles, but remain in memory. However, when a "low-memory condition occurs the system may purge suspended apps without notice to make more space for the foreground app", Apple says in the document linked above. These apps remain in the multitasking tray unless removed.

What does this mean?
This method of memory management leads to the last few (or couple, or none) of the apps running in the background, based on what you're currently doing.

Try this little experiment to understand what I'm saying:
Get your hands on an iOS device and open the Settings app. If you have been using it lately, force close it from the multitasking bar. When you open it afresh, you'll notice that the various buttons, text and the left pane takes a few seconds to render. At least this is noticeable on my iPad 2 (running iOS 5) and I'm guessing that certainly on the first iPad.

Now close it (just the Home button or pinch; not from the multitasking tray) and open Safari. Now close Safari and go back to the Settings app (or use the multitasking tray to switch to it). Notice that it doesn't take a while to draw everything.

Now close it (again, not from the tray; just Home button) and open a more demanding app. Open Garageband if you have it. Play a game. Or just open Safari and browse to several websites. We are doing this to fill up the memory and push the Settings app into the depths.

Lastly, open Settings again and notice that it takes a second or so to render again. You had, in fact, caused the Settings app to close completely while demanding more memory from iOS.

You can do this experiment with many different apps instead of Settings. Maybe open a game that starts with a splash screen when closed completely but doesn't when you just switch to it after doing a bit of something else. I think Angry Birds works well.

So should I close apps or not?
No. You don't need to. When the current task requires more memory, iOS will close older apps, which will remain as a list in the multitasking tray. Think of removing the last few apps from the tray as "force quitting" them in OS X. However, clear more than a few apps and you're just cleaning a history list, basically.

I probably have more than 60 apps "running" in the multitasking tray of my iPad 2 and I keep using it normally. The battery runs perfectly and there are no frequent crashes or freezes either (these can occur if you're using not-so-well-designed-apps too).

Share/Bookmark