Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Android garbage collector pausing other apps while running?

I've found some information about the Android garbage collector that are contradictions to me.

Android Devevelopers Guide says:

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

Ok, now the other thing

According to this link: The Dalvik Virtual Machine Architecture android uses mark and sweep aproach.

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.

If we check how mark and sweep works on this link: Mark and Sweep Garbage Collection Algorithm , we can see this:

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.

So my question now is, how does it really work? Does garbage collector pause everything while he is working, or is he capable of running completely independent on the other active processor core?

like image 569
Drag0 Avatar asked Feb 12 '13 19:02

Drag0


People also ask

Does garbage collector pause?

Garbage collection (GC) is the process by which Java removes data that is no longer needed from memory. A garbage collection pause, also known as a stop-the-world event, happens when a region of memory is full and the JVM requires space to continue. During a pause all operations are suspended.

How does the garbage collector work in Android?

The Garbage Collector in Dalvik uses the Concurrent Mark and Sweep algorithm mentioned earlier. unreferenced objects aren't reclaimed immediately. Instead, the gathering is delayed until all available memory has been exhausted, meaning that short-lived objects remain in memory tons longer after they become unused.

Why does garbage collection take so long?

If your application's object creation rate is very high, then to keep up with it, the garbage collection rate will also be very high. A high garbage collection rate will increase the GC pause time as well. Thus, optimizing the application to create fewer objects is THE EFFECTIVE strategy to reduce long GC pauses.

Does Android have garbage collection?

Any time a generation starts to fill up, the system executes a garbage collection event in an attempt to free up memory. The duration of the garbage collection depends on which generation of objects it's collecting and how many active objects are in each generation.


1 Answers

The Dalvik VM in the Gingerbread and beyond version is using the Mostly Concurrent partial collection garbage collector with pause times usually around 5ms. Therefore, yes, the GC is influencing the other apps by stopping them but the concurrent GC algorithm is able to minimaze these pauses.

You should look at :

  • Technical details of Android Garbage Collector
  • Does the DalvikVM Garbage Collector halt the whole VM?

In general, the Garbage Collection theory [Garbage Collection Wiki] explains:

  • Stop-the-world garbage collectors completely halt execution of the program to run a collection cycle

  • Incremental and concurrent garbage collectors are designed to reduce this disruption by interleaving their work with activity from the main program. Incremental garbage collectors perform the garbage collection cycle in discrete phases, with program execution permitted between each phase (and sometimes during some phases).

  • Concurrent garbage collectors do not stop program execution at all, except perhaps briefly when the program's execution stack is scanned.
like image 65
Aleš Avatar answered Oct 22 '22 23:10

Aleš