Android垃圾收集器的技术细节

Technical details of Android Garbage Collector(Android垃圾收集器的技术细节)

本文介绍了Android垃圾收集器的技术细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我正在研究各种移动平台的共性/差异时,正在研究的一个方面是内存管理.因此,我对各种机制的更详细技术信息感兴趣.

As I'm doing a research on commonalities/differences of various mobile platforms, one of the aspects under investigation is memory management. As such, I'm interested in more detailed technical information on the various mechanisms.

具体来说,例如Android 使用哪种垃圾收集器类型?
([Google Groups Discussion] 建议它正在使用跟踪"机制 - 但我希望有一个更官方"的来源,我可能会引用它,并希望在那里找到信息该类型可能对程序员产生的影响).

In specific, e.g. which garbage collector type does Android use?
([Google Groups Discussion] suggests that it is using "tracing" mechanism - but I'd appreciate a "more official" source which I could possibly quote, plus hoping to find information there which implications the type could have on the programmer).

还有一个问题是Android 3.0 (Honeycomb) 中的 GC 以何种方式进行了专门调整以利用多个处理器?
[Android 开发者指南] 建议

Also among my questions is in what way the GC in Android 3.0 (Honeycomb) has been tweaked specifically to utilize multiple processors?
[Android Devevelopers Guide] suggests that

Android 3.0 是该平台的第一个版本,旨在在单核或多核处理器架构上运行.Dalvik VM、Bionic 库和其他地方的各种变化增加了对多核环境中对称多处理的支持.这些优化可以使所有应用程序受益,甚至是那些单线程的应用程序.例如,如果有两个活动核心,如果 Dalvik 垃圾收集器在第二个核心上运行,单线程应用程序可能仍会看到性能提升.系统会自动安排."

Android 3.0 is the first version of the platform designed to run on either single or multicore processor architectures. A variety of changes in the Dalvik VM, Bionic library, and elsewhere add support for symmetric multiprocessing in multicore environments. These optimizations can benefit all applications, even those that are single-threaded. For example, with two active cores, a single-threaded application might still see a performance boost if the Dalvik garbage collector runs on the second core. The system will arrange for this automatically."

和以前一样,我宁愿找到包含更多技术信息的来源来阅读此内容.再说一次,对开发人员有什么影响(除了显然希望提高性能之外)?

As before, I'd rather find a source with more technical information to read upon this. Again, what's the impact on the developer (other than the obvious that increased performance could be hoped for)?

感谢任何此类输入.

谢谢!

推荐答案

为了回答您的一个问题,Dalvik VM 确实使用跟踪垃圾收集器,使用 Mark and Sweep 方法.

To answer one of your questions, the Dalvik VM indeed does use a tracing garbage collector, using a Mark and Sweep approach.

根据 Dalvik 虚拟机架构:

Dalvik 垃圾收集器中当前的策略是保留标记位,或指示特定对象可访问"的位和因此不应该被垃圾收集,与其他堆内存分开.

The current strategy in the Dalvik garbage collector is to keep mark bits, or the bits that indicate that a particular object is "reachable" and therefore should not be garbage collected, separate from other heap memory.

从 Android 5.0 (Lollipop) 及更高版本开始,Dalvik 被替换为 Android Runtime (ART).

From Android 5.0 (Lollipop) and on, Dalvik was replaced with the Android Runtime (ART).

关于垃圾收集器从 Dalvik 到 ART 的变化,Google 有以下说法(来源):

Google has the following to say about the changes in the garbage collector from Dalvik to ART (source):

垃圾收集 (GC) 会损害应用的性能,从而导致断断续续的显示、较差的 UI 响应能力和其他问题.艺术从几个方面改进垃圾收集:

Improved garbage collection

Garbage collection (GC) can impair an app's performance, resulting in choppy display, poor UI responsiveness, and other problems. ART improves garbage collection in several ways:

  • 一次 GC 暂停而不是两次
  • 在剩余的 GC 暂停期间进行并行处理
  • 具有较低总 GC 时间的收集器,用于清理最近分配的短期对象的特殊情况
  • 改进了垃圾收集人机工程学,使并发垃圾收集更加及时,这使得 GC_FOR_ALLOC 事件极其在典型用例中很少见压缩 GC 以减少后台内存使用和碎片

另见:

  • 源代码Dalvik 垃圾收集器
  • ART垃圾回收器源码

这篇关于Android垃圾收集器的技术细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android垃圾收集器的技术细节

基础教程推荐