Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the DalvikVM Garbage Collector halt the whole VM?

I have a situation in which an my Android application is not able to perform a soft real time task well in time as Garbage Collector is called which takes a few milliseconds. The few ms of time given to GC is inadequate to miss some important deadline for small tasks of reading data from IO device.

I was thinking about introducing another thread and giving it the task of polling the important data. However I'm not sure if GC suspends all threads or just the memory hogging ones?

like image 972
sharjeel Avatar asked Dec 01 '12 08:12

sharjeel


People also ask

How does Android garbage collection work?

Garbage collection A managed memory environment, like the ART or Dalvik virtual machine, keeps track of each memory allocation. Once it determines that a piece of memory is no longer being used by the program, it frees it back to the heap, without any intervention from the programmer.

What is garbage collector?

Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java. A GC-enabled programming language includes one or more garbage collectors (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program.

Can you manually call the garbage collector Android?

Generally speaking, in the presence of a garbage collector, it is never good practice to manually call the GC. A GC is organized around heuristic algorithms which work best when left to their own devices. Calling the GC manually often decreases performance.


1 Answers

In Memory Management for Android Apps by Patrick Dubroy I found the following (slide 16, emphasis mine):

  • Pre-Gingerbread GC:

    • Stop-the-world

    • Full heap collection

    • Pause times often > 100ms

  • Gingerbread and beyond:

    • Concurrent (mostly)

    • Partial collections

    • Pause times usually < 5ms

In general, garbage collection must stop the whole VM, although nowadays this time greatly reduced. However neither VM nor Android platform as a whole are not real-time operating systems so don't expect such strict guarantees.

Why do you need single millisecond precision?

like image 65
Tomasz Nurkiewicz Avatar answered Nov 15 '22 08:11

Tomasz Nurkiewicz