Android内存回收的五个优先级(译)

Android内存回收的五个优先级(译)


翻译目的:为了更好的了解内存回收机制。
提前声明:英文很烂,翻译仅供个人学习。
原文传送门:http://developer.android.com/intl/zh-tw/guide/components/processes-and-threads.html

以下按优先级排序

  • Empty process(First blood
    原文:A process that doesn’t hold any active application components. The only reason to keep this kind of process alive is for caching purposes, to improve startup time the next time a component needs to run in it. The system often kills these processes in order to balance overall system resources between process caches and the underlying kernel caches.
    : 进程中不含有任何处于活跃状态下的应用组件,它存在的唯一目的是为了提供缓存,来缩短下一次的启动组件的时间。系统经常会为了自身整体资源而适当调节进程缓存与底层内核缓存。
    (ps:process翻译成进程or过程还是其他的呢?)

  • Background process
    原文:A process holding an activity that’s not currently visible to the user (the activity’s onStop() method has been called). These processes have no direct impact on the user experience, and the system can kill them at any time to reclaim memory for a foreground, visible, or service process. Usually there are many background processes running, so they are kept in an LRU (least recently used) list to ensure that the process with the activity that was most recently seen by the user is the last to be killed. If an activity implements its lifecycle methods correctly, and saves its current state, killing its process will not have a visible effect on the user experience, because when the user navigates back to the activity, the activity restores all of its visible state. See the Activities document for information about saving and restoring state.
    :进程中含有一个当前对用户不可见的Activity(该Activity的onStop()方法已经被调用),这样的进程不直接影响用户的体验,且系统能在任何时候为了当前显示的内容、可见内容、或服务进程而结束这些进程进而回收利用记忆体。通常在后台运行着许多进程,因此他们被放在一个LRU(最近最少被使用)list中以确保最近被用户看到的Activity其进程是最后被结束的。假如一个Activity正确的执行了他生命周期的方法。并且保持了他当前的状态。结束它的进程将不会对用户体验产生明显的影响。因为当用户返回这个Activity时,该Activity将恢复所有的可见状态。请参阅活动 有关保存和恢复状态信息的文档。


  • Service process
    原文:A process that is running a service that has been started with the startService() method and does not fall into either of the two higher categories. Although service processes are not directly tied to anything the user sees, they are generally doing things that the user cares about (such as playing music in the background or downloading data on the network), so the system keeps them running unless there’s not enough memory to retain them along with all foreground and visible processes.
    :进程中正运行一个已通过startService()启动的Service,并且不会落入任一两个较高类别(不明白原文意思)。虽然Service进程不直接与用户所看到的内容有联系,但是它们通常都是执行用户所关心的任务(如后台播放音乐或从网络上下载数据),因此系统只有在记忆体不能维持这些进程与所有的前台显示内容和可见进程(下文)同时进行时才会结束他们。


  • Visible process
    原文:A process that doesn’t have any foreground components, but still can affect what the user sees on screen. A process is considered to be visible if either of the following conditions are true:

    1. It hosts an Activity that is not in the foreground, but is still
      visible to the user (its onPause() method has been called). This
      might occur, for example, if the foreground activity started a
      dialog, which allows the previous activity to be seen behind it.
    2. It hosts a Service that’s bound to a visible (or foreground) activity.

    A visible process is considered extremely important and will not be killed unless doing so is required to keep all foreground processes running.
    :该进程不含有任何前台显示的组件,但是仍然能对用户在屏幕上所看到的内容产生影响。当进程满足以下的条件的时候被视为可见的。

    1. 承载着一个不在前台显示的Activity,但是他仍然对用户可见(Activity的onPause()已经被调用)。Activity有可能出现。举例,假如前台显示的Activity开启一个Dialog,该Dialog允许之前Activity在它之下被看到。
    2. 承载一个绑定在可见或前台显示的Activity的Service
      一个可见的进程是极为重要的,除了需要维持所有前台进程运行而才结束进程时之外是不会结束了的。

  • Foreground process
    原文:A process that is required for what the user is currently doing. A process is considered to be in the foreground if any of the following conditions are true:
    1. It hosts an Activity that the user is interacting with (the Activity’s onResume() method has been called).
    2. It hosts a Service that’s bound to the activity that the user is interacting with.
      It hosts a Service that’s running “in the foreground”—the service has called startForeground().
    3. It hosts a Service that’s executing one of its lifecycle callbacks (onCreate(), onStart(), or onDestroy()).
    4. It hosts a BroadcastReceiver that’s executing its onReceive() method.
      Generally, only a few foreground processes exist at any given time. They are killed only as a last resort—if memory is so low that they cannot all continue to run. Generally, at that point, the device has reached a memory paging state, so killing some foreground processes is required to keep the user interface responsive.
      :改进程处理着用户的当前任务。当它满足以下条件时被视作前台显示的进程
      1.承载着一个正与用户交互的Activity(该Activity的OnResume()已经被调用)
      2.承载一个绑定在正在与用户交互的Activity的Service上。承载的Service正在运行在前台,且已经调用了startForeground()方法
      3.承载一个正在执行生命周期中的某一回调函数 (onCreate(), onStart(), or onDestroy());
      4.承载着一个正在执行onReceive()的BroadcastReceiver。
      总的来说,只有一小部分的前台显示进程在任何给定时间存在。他们只有在最后的情况下才会被结束——记忆体容量太低不能继续 运行。通常,在这一点上,该装置已经达到了一个内存分页状态,所以杀死某些前台进程必须保持用户界面的响应。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值