In a world where Android users rival iOS users for superiority one of the major points Android users tend to gloat about is the amount of RAM their devices carry. For instance, Samsung’s Note 20 offers up to 12GB of RAM while Apple’s iPhone 12 Pro is the first iPhone to come with 6GB of RAM an upgrade from the previous 4GB in all their flagships.
So why do iPhones get less amount of RAM and still perform the same (if not better) than Android phones with significantly larger amounts of RAM? It all has to do with the fundamental difference in the way iOS and Android handle apps. According to Glyn Williams over on Quora, iOS devices run better than Android devices with twice the RAM because Android apps use Java, and need all the extra RAM to do garbage collection.
From the very beginning, Android was designed to support many different processor types, many different manufacturers, and many different hardware configurations. Normally, software written for one kind of system can’t just run on another; it has to be “ported” over, which often involves rewriting the incompatible bits.
What’s garbage collection? It’s a process that triggers the recycling of memory once an Android app is done using it. Usually, this works pretty well on systems that have a lot of free RAM, but once you get a lot of different apps running, things start getting dicey. A large part of Android (and Android apps) are generally written in Java because it is the official language for Android development. Due to how Java is configured, memory released by apps that are not in use anymore has to be recycled back to the device via the garbage collection process. Unused memory (garbage) has to be cleaned and recycled to the system so it can be used by other apps. Garbage collection is super effective for the smooth running of Android devices but the problem is that the process itself needs a sufficient amount of RAM.
According to Williams, Android’s garbage collectors work best when Android apps have 4 to 8 times as much memory as is actually needed in order to perform the garbage collection process. Once you stop having that amount of free memory available, performance starts suffering.
iOS vs Android
Apple exerts a lot more control over the entire iOS ecosystem. If you want to use iOS, then you only have one option for a phone: the iPhone. Apps for the Apple store are created using Apple’s tools only because Apple knows the exact specifications of every single device that will ever run its operating system, thus can make design decisions accordingly. Additionally, all iOS apps are compiled to native code, and that code is executed directly on the hardware. No need for a virtual machine means significantly less RAM used overall.
iOS, therefore, needs less RAM to run more smoothly than Android does since it was designed to avoid garbage collection from scratch therefore only needing the memory it’s using. What a radical idea, huh?
Source – Quora