27

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.

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).

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 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)?

Any such input is appreciated.

Thanks!

Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
vaiomike
  • 503
  • 1
  • 6
  • 14

1 Answers1

27

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

According to The Dalvik Virtual Machine Architecture:

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.

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

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

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:

  • One GC pause instead of two
  • Parallelized processing during the remaining GC pause
  • Collector with lower total GC time for the special case of cleaning up recently-allocated, short-lived objects
  • Improved garbage collection ergonomics, making concurrent garbage collections more timely, which makes GC_FOR_ALLOC events extremely rare in typical use cases Compacting GC to reduce background memory usage and fragmentation

See also:

Sebastian Paaske Tørholm
  • 49,493
  • 11
  • 100
  • 118
  • 2
    I take it from your great links that "The main disadvantage of the mark-and-sweep approach is the fact that that normal program execution is suspended while the garbage collection algorithm runs. In particular, this can be a problem in a program that interacts with a human user or that must satisfy real-time execution constraints. For example, an interactive application that uses mark-and-sweep garbage collection becomes unresponsive periodically." Would be interesting to find technical details on how and to what extent Honeycomb's support for multiprocessors can mitigate this disadvantage!? – vaiomike Feb 01 '11 at 11:09
  • 1
    So there's no copying involved whatsoever between heap spaces (e.g. from eden space to other spaces?) i.o.w. Android's GC does not use any form of generational/statistical collection strategies? – mxk Sep 05 '12 at 14:13
  • 2
    Looking at the source code, I see its marking white, black and grey, so it appears to be tri-color marking. – Lucy Apr 17 '13 at 01:36
  • @mr.icetea: The post has been updated both to fix the Dalvik links, and to include a comment about ART, the current Android runtime. – Sebastian Paaske Tørholm Nov 23 '15 at 13:17