An analysis of memory management principles for Android

Source: Internet
Author: User
<span id="Label3"></p><p><p>Android takes a different process management strategy from linux, and unlike linux, which ends the process after the process activity has stopped, Android keeps the processes in memory until the system needs more memory. These processes, which are kept in memory, typically do not affect the speed of the overall system, and increase the startup speed of the process when the user activates the processes Again.</p></p><p><p>When does Android end the process? Which process does it end? The common understanding was that Android was based on a list of the most recently used programs called LRU (last recently used), sorted the program, and ended the oldest process.</p></p><p><p></p></p>In fact, the memory management mechanism of Android is this, as Follows: <ol class="exp-conent-orderlist"> <ol class="exp-conent-orderlist"> <li class="exp-content-list list-item-1"><p>The importance of the process is evaluated and the importance is expressed in terms of the value "oom_adj", which is given to each process, (the system determines which processes need to end according to "oom_adj"), in general, the higher the value of "oom_adj", the higher the likelihood that the process will be terminated by the system Selection)</p><p></p><p></p><p>2. The "oom_adj" value of the foreground program is 0, which means it will not be terminated by the system, once it is inaccessible, it will get a higher "oom_adj", we speculate that the value of "oom_adj" is determined by the location of the software in the LRU list;</p></li> <li class="exp-content-list list-item-3"><p>3.Android is different from linux, has its own unique process management module, This module is more customizable, can be based on the "oom_adj" value of the scope to determine the process management policy, such as can be set "when memory is less than x, the end of" Oom_adj "greater than y process". This gives the process management script the option to write More.</p><p><span class="last-item-end">END</span></p></li> </ol> </ol>Android divides the process into six major categories: <ol class="exp-conent-orderlist"> <li class="exp-content-list list-item-1"><li class="exp-content-list list-item-1">1<p>Foreground process (foreground): The process currently being displayed on the screen and some system Processes. For example, a system process such as Dialer Storage,google search is the foreground process, and for example, when you run a program, such as a browser, when the browser interface is displayed in the foreground, the browser belongs to the foreground process (foreground). But once you press home to return to the main screen, the browser becomes a daemon (background). The last process we want to terminate is the foreground process.</p><p></p></li></li> <li class="exp-content-list list-item-2"><li class="exp-content-list list-item-2">2<p>Visible process (visible): Visible process is some no longer the foreground, but the user is still visible process, for example: widgets, input method, etc., are Visible. Although this part of the process is not in the foreground, but also closely related to our use, we do not want them to be terminated (you certainly do not want the clock, weather, news and other widgets are terminated, then they will not sync, you do not want the input method is terminated, or you need to restart input input every Time)</p><p></p></li></li> <li class="exp-content-list list-item-3"><li class="exp-content-list list-item-3">3<p>Secondary services (secondary server): Some of the services currently running (major services, such as dialing, are not likely to be terminated by process management, so this is only a minor service), for example: Google Enterprise suite, gmail internal storage, contact internal storage, and so On. Although this part of the service is a secondary service, but some of the system functions are still closely related, we often need to use them, so we also hope they are terminated</p><p></p></li></li> <li class="exp-content-list list-item-4"><li class="exp-content-list list-item-4">4<p>. Background process (hidden): Although the author uses the word hidden, it is actually a background process (background), which is the process that we generally understand to be switched to the background after startup, such as a browser, a reader, and so On. When the program is displayed on the screen, the process that he runs is the foreground process (foreground), and once we press home to return to the main interface (note that by pressing home, not pressing back), the program resides in the background and becomes the background process (background). Background process Management policy has a variety of: in a more positive way, once the program arrives in the background immediately terminate, this way will increase the speed of the program, but can not speed up the program to start again, there are more negative ways, as much as possible to retain the background program, although it may affect the speed of a single program, however, the speed is increased when you start a program that has started Again. This will require users to find a balance based on their own usage habits.</p><p></p></li></li> <li class="exp-content-list list-item-5"><li class="exp-content-list list-item-5">5<p>Content Provider: There is no program entity to provide content for other programs to use, such as calendar supply nodes, Mail Supply nodes. This type of procedure should have a higher priority when the process is terminated</p><p></p></li></li> <li class="exp-content-list list-item-6"><li class="exp-content-list list-item-6">6 NULL Process (empty): There is nothing in the process of running, some programs, such as bte, after the program exits, will still reside in the process of an empty process, the process is not any data running, the role is often to improve the Program's next startup speed or record some of the history of the program Information. This part of the process is undoubtedly the first to be Terminated.<br><p>Simply put, when you opt out of the program, you do not exit the program completely, and the program will still host a process in the background so that it can open more quickly next Time. When is the program completely closed? This depends on the type of the program (which is the type mentioned above). The system will give each type of program a memory threshold (valve), that is, when running memory below a certain value, the system will automatically follow the opening sequence to close the type of Program. For example, when the storage is less than 24MB, the system will automatically close the empty process of this type of program, releasing more memory for the new program to use, has guaranteed the normal operation of the new Program.</p><p><span class="last-item-end">END</span></p></li></li> </ol>Summarize <ol class="exp-conent-orderlist"> <ol class="exp-conent-orderlist"> <li class="exp-content-list list-item-1">1<p>To sum up, we are not difficult to see, many times we do not need too much attention to the system of free memory (RAM) is how much, there is no need to deliberately kill the background program, because the system will automatically allocate memory to ensure the operation of new programs, except for special circumstances, such as you will open a very big game, Need more memory, This time you can manually kill some background programs, to ensure the smooth Game.</p></li> </ol> </ol><p><p>An analysis of memory management principles for Android</p></p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.