Android And iOS Memory Management, And How Are They Different

Android and iOS, two popular operating systems that power almost all mobile devices on the planet.

While they have many similar things, with one copying another, the two can't be anymore different. Not necessarily because one operating system is better (or worse) than the other, but differences do exist in their memory management.

Before digging any deeper. memory management here means how the two operating systems make use of their RAM (Random Access Memory).

RAM can be defined as a way computers (and smartphones) access stored files. Unlike hard drive (local storage), RAM is a temporary storage. What this means, things that are stored inside RAM, aren't permanent like those stored inside hard drives.

Since smartphones are devices with a more limited size, there's a small difference between how RAM is used on these devices versus how it's used on computers. However, they are basically the same, as it is used to deliver instructions and data to the processor so it can be processed, reducing load time and allow users to move from one app to another quickly and without any hassles.

What is RAM used for, is to read data when the system needs it. Since RAM delivers data a lot quicker than when the data is stored inside the local storage, the more RAM a device has, the speedier it should be.

Apparently, this is not always true.

Related: Choosing Between IOS And Android: Which Is Best For You?

Apple vs. Android

If we see how much memory Android phones have, they do have quite a lot. In fact, they can have more RAM than many desktop computers, and much more than Apple's iPhones.

But does that mean Android is better at multitasking? Or does it make iPhones less capable in running complex games? The answer is no.

This is because of the differences in their memory management.

On Android phones, complicated things happen when users are multitasking or running apps side-by-side. With virtual memory, these devices allow apps to run on their own virtual space. In Android's case, the memory is given to the system, but the other part is divided to be used by each apps.

Any RAM that isn't in use, is free.

However, a good operational system shouldn't have any free RAM, but available RAM. Here, Android manages its RAM for things like caching storage when users reuse an app, and keep the system to always use RAM to relocate data. This allows the operating system to quickly switch from one app to another, from one screen to the next, with relative ease, as long as there is RAM available.

The main disadvantage of this Android memory management, is the way Google and other developers handle their apps. From the way they are built and created, to how they behave in the background.

This can make complicated issues.

Android architecture

Going a bit deeper, Android uses Java. For good reasons, Java can run on any processor. What this means, it can be ported by many smartphone manufacturers running different hardware configuration.

But the disadvantage is that it runs via a virtual machine, which is like a virtual computer layer between the actual hardware and the software (Java software in Android’s case).

This is a huge disadvantage because a lot of memory is needed to run this virtual-machine, and even more memory is needed to store both the Java byte-code and the processor machine-code, as well as store the system-needed resources for translating the Java byte-code into the device’s processor machine-code.

Lastly, this virtual machine is built around a method called 'garbage collection.'

Apps on Android are actually encouraged to use as much RAM as they need, taking advantage of the available RAM whenever possible. When users use the Android phone by opening new apps and do things, the garbage collection's job is to traverse the heap, enumerate all objects allocated by those apps, mark all reachable objects, to then free up whatever RAM is left remaining.

In short, garbage collection is essentially a way for Android to recycle memory once an Android app is done using it.

While this method is effective, it works by consuming much RAM. Otherwise, the system will spend too much time collecting garbage that it will ruin overall performance. Problems can also happen when users have a lot of apps running.

Android memory
Android prioritizes apps users are currently using, putting less importance to other apps in the background

How about iOS?

Most notably, iPhones have less RAM than Android phones. But Apple has a reason for that: it doesn't need as much.

For the first thing, Android apps are freer. What this means, they can access services or perform post-processing background tasks in less restriction than in iOS. This is a good thing, but it can be bad when apps behave in weird ways because of that freedom.

For example, developers of an Android app can make the app to stay persistent in the background. This consumes RAM that otherwise can be used by other apps.

Android operating system that is based on Linux, chooses to stop apps running in the background when available RAM runs low in order to free up for new apps that users are opening, iOS on the other hand, squeezes more data from apps running in the background compared to Android at a system level.

Whereas in iOS devices, Apple has a more controlled strategy. In this case, the operating system chooses whether an app can do something or not when it's running in the background.

What this means, iOS allows users to open more apps and having them running the background, longer after users have finished using them.

Then there is iOS that was designed to run Objective-C applications on known hardware, which is an ARM processor. Because Apple has full control of the hardware, the company could easily make the decision to have native machine code (without virtual machine) running directly on the processor.

This practically saves a lot of memory requirement.

Android’s original virtual machine, Dalvik, was built in a time where the smartphone industry has yet to know what CPU architecture would dominate the mobile world. At that time, it was designed to use the x86, ARM and MIPS with room to add future architectures as needed.

The original iPhone which picked up significant popularity when it was first launched, made a revolution that resulted in the industry moving almost entirely to use the ARM architecture. So here, Dalvik's compatibility with more architectures, became somehow useless.

Read: Too Many Android Phones On The Market? Here Are The Reasons

What's more, iOS doesn't have that 'garbage collector'. Instead, every object created on the operating system has a count associated to it. This is called the 'Retain Count.'

A newly created object, will be given a count of 1. During the course of the object's life cycle, the Retain Count can increase of decrease accordingly. But the rule here is that once the Retain Count reaches 0, the operating system immediately terminates the object.

When Apple introduced 'Automatic Reference Counting' (ARC), iOS can automate the process, with the complier inserting the appropriate Retain Count to the code before building the binary.

This memory management capability is a major advantage over Android's garbage collection. This is, for reasons, part of why iOS devices run so fast, while having lower specifications.

iOS Retain Count
Apple in using Retain Count on iOS

Looking at the market, the fact is clear: Android phones have humongous RAM, that increases all the time.

An example of this reason:

If users close a web browser, to then relaunch it, the browser will opens the last page they were on. his is because the system saves the URL, not the actual page. This happens because Android has a mechanism which sends a warning to apps running in the background to store the most important information because when RAM is low, the app can be terminated.

This means the app only keeps what's extremely important.

Because of this particular reason, Google and other manufacturers will always opt for more RAM in their devices as an alternative to keep processes running efficiently without having to terminate them all the time.

But for iOS, Apple has a software-driven solution: its iOS operating system is less dependent to hardware. This is because iOS runs natively on the hardware, unlike Android.

For these reasons, Android and iOS specifications comparison, don't always add up. Most of the time, even Android phones with twice the RAM size, can perform poorly if compared to iPhones.

While the two operating systems have their own advantages over the other, the RAM usage and management on both operational systems is quite similar and efficient. The main differences in how they manage their RAM, is in the way they handle apps that run in the background.

Android tried solving some its memory issues, one of which is by using Android RunTime (ART) which replaced Dalvik. This runtime is optimized to take advantage of the target processors as much as possible, but without adding any necessary compatibility for new architectures.

ART is written to run multiple virtual machines on low-memory devices by executing DEX files, a bytecode format designed specially for Android that's optimized for minimal memory footprint.

This makes Android to have performance improvements transparent to end users.

Further reading: Google And Apple, The Two Giants That Control The Mobile Internet