Arbitrary access memory (RAM) is an important asset in any product advancement environment, however it’s significantly more profitable on a portable working framework where physical memory is frequently obliged. In spite of the fact that Android’s Dalvik virtual machine performs routine trash gathering, this doesn’t permit you to overlook when and where your application distributes and discharges memory.
All together for the junk jockey to recover memory from your application, you have to abstain from presenting memory spills (generally brought on by clutching object references in worldwide individuals) and discharge any Reference objects at the fitting time (as characterized by lifecycle callbacks talked about further underneath). For most applications, the Dalvik junk jockey deals with the rest: the framework recovers your memory assignments when the relating objects leave the extent of your application’s dynamic strings.
This record clarifies how Android oversees application procedures and memory distribution, and how you can proactively decrease memory utilization while creating for Android. For more data about general practices to tidy up your assets when programming in Java, allude to different books or online documentation about overseeing asset references.
How Android Manages Memory
Android does not offer swap space for memory, but rather it uses paging and memory-mapping to oversee memory. This implies any memory you alter—whether by assigning new protests or touching mapped pages—stays occupant in RAM and can’t be paged out. So the best way to totally discharge memory from your application is to discharge object references you might hold, making the memory accessible to the trash specialist. That is with one special case: any documents mapped in without alteration, for example, code, can be paged out of RAM if the framework needs to utilize that memory somewhere else.
In order to fit everything it needs in RAM, Android tries to share RAM pages across processes.