RAM Management for Android

RAM management for Android refers to all the techniques used by an operating system to manage memory (RAM).

Memory management is very important for modern smartphones today. It is a huge part of our multitasking experience. A smartphone with excellent RAM management tends to provide a good user experience. A smartphone with bad RAM management does the opposite, i.e. provides anger and frustration.

The following are some of the techniques used by smartphones (as well as other computers) to manage RAM. These include:

  • Paging and Memory mapping
  • Memory allocation
  • Garbage collection
  • Out of memory operations
  • Caching and swapping

Read: Multitasking on smartphones explained


Paging and Memory mapping

Paging refers to the way that an operating system software divides the RAM into units. These units, called pages, are assigned to apps or other running process.

The folks at Apple are very secretive so I could not find any info about iOS.

Android on the other hand is transparent as it is open sourced. It 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. An App like PES, PUBG or Chrome may require more than 375,000 pages or 1.5GB of RAM.

Memory mapping refers to how the software or virtual memory locations is mapped on to the physical memory (RAM). This is done by what is known as a memory management unit. It maps all software locations of memory on to the hardware and then hands over a virtual address book to the OS.


Memory allocation

Memory allocation refers to ways that the operating system assigns RAM space to running programs in memory. Some operating systems tend to assign entire page frames to running apps. Android on the other hand tends to assign shared RAM pages.

For example, the size of a RAM page is 4KB. If an app (XYZ) requires 2KB, some OS would assign the entire 4KB to that app. This sometimes leads to fragmentation. Android on the other hand would give 2KB to the XYZ app and then assign the remaining 2KB to another app. This is a much more effective way of allocating memory.


Garbage collection

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

Many operating systems have ways of automatically detecting memory allocated to every process in RAM. When that process is no longer in use, the operating system deletes the process and the freed memory is reallocated to other tasks.


Out of memory (OOM) operations

This is when a computer runs out of memory (both RAM and virtual memory). As a result, it will be unable to load any new app or carry out new tasks. This is sometimes referred to as thrashing.

Most OS memory managers kick into overdrive at this point and try to reclaim as much space as possible. This is also sometimes referred to as aggressive RAM Management.


Caching and swapping

When an app is no longer (running or) actively in use both in the foreground and background, the OS saves (caches) it. It could leave the cache file on the main RAM or it could move it elsewhere.

Swapping is the process of moving a cache file off the main RAM to the zRAM or virtual memory. Such apps are usually in a sleeping state and will be moved back to the RAM, the minute they are required.

In OOM cases, the OS memory manager could move the cache off to the internal storage and clear out the data that is not needed.


Benefits of proper RAM Management

  1. Smooth user experience
  2. Snappy command response
  3. Better multitasking and app switching
  4. Minimum lag
  5. Apps stay in memory for longer
  6. Smartphone doesn’t hang or complains about low memory

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 *