How Android Manages RAM

Android is the most widely used operating system in the world. Since its inception in 2007, it has gone on to dominate the market and conquer the world. In this post, we are going to look at how Android manages RAM.

RAM is a very common subject of discussion these days but it is not very understood. Not by a lot of people. RAM is a very fast type of memory that sits very close to the SoC. It serves as a space for the CPU core to process apps as well do multitasking.

The smartphone’s operating system is usually in charge of RAM management and Android is no different.

How Android Manages RAM

Android memory management is done by Android Run Time (ART). The ART replaced the older Dalvik Virtual Machine (DVM) which was used to oversee how Android ran on smartphones.

The ART was a great improvement over the older DVM. ART improved system efficiency and reduced battery consumption. In addition, ART improved app loading times and RAM management.

ART helps Android manage RAM efficiently using the following methods:

  • Paging
  • Memory mapping
  • Memory allocation
  • Caching and app switching
  • Garbage collection

Paging and Memory mapping

Android divides RAM into pages and each page is about 4KB in size. An app like WhatsApp for example may only need 30 pages or 120KB of RAM. On the other hand, an app like PES, PUBG, or the Chrome browser may require more than 375,000 pages or 1.5GB of RAM.

Memory mapping refers to how the software or virtual memory locations are mapped onto the physical memory (RAM). This is done by the Memory Management Unit. It maps all software locations of memory onto the hardware and then hands over a virtual address book to the OS.

See: RAM management

Memory allocation

Memory allocation refers to how ART shares memory (RAM space) amongst competing apps.

ART does not allocate full RAM pages to apps because apps may not use all of the space on the page. This would lead to wasted pages. What it does instead, is that it shares RAM pages between apps. This is a much more efficient way to allocate memory as it prevents memory fragmentation.

ART also puts a restriction on the amount of RAM space that can be allocated to any single app. This is usually around 4GB but it can vary depending on the size of the RAM. This is to ensure no one single app uses up RAM to the detriment of the others as well as general system functions.

Read: Causes of poor RAM management

Caching and App switching

When a user is finished with an app and switches to a different one, the ART does not immediately kill it. What it does is that it keeps the app process in a cache. It may also choose to keep this cache on the RAM or swap it to the zRAM or off the RAM to a virtual memory storage.

When the app is needed, ART simply moves the app from the cache and back into the RAM. Simple, efficient, and effective.

Read: Multitasking and RAM Management on smartphones

Garbage collection

Garbage collection refers to the way that an OS recovers memory from app processes that are no longer in use.

ART has ways of automatically retrieving space from app processes that have been killed or cached. It would then allocate this freed space to newer apps and thus improve system performance.

Please leave a comment if you have any difficulty and remember to:

Leave a Reply

Your email address will not be published. Required fields are marked *