One of the most underrated achievements of Android ecosystem is how much garbage collection has improved in last 6 releases of Android improving life of both users and developers.

A thread 🧵
Garbage collection is good..and bad. Good because it gives a free memory, bad because it pauses application thread itself (mo memory mo problems)
Erstwhile Dalvik Runtime(Android 4.4 and below) used Mark and Sweep Algorithm for GC. It involved two pauses of app thread to complete GC itself, not very good for smooth UI or animations.
But memory released was fragmented. If 3 GC pauses released x,y,z amount of memory, they would lie around as a separate memory space. Now if a Bitmap being loaded requests memory more than x,y or z, it won't get it and it will trigger another GC to reclaim such space or throw OOM
ART overhauled GC starting with Android 5.0. GC pauses were reduced to 1 with the application process taking up the job of marking objects. Allocations of large objects like Bitmap is moved to separate space which helps manage fragmentation issues and reduces GC triggers.
The GC also maintains young objects separately which are recently allocated and are short lived. This allows smaller GC pauses where these objects can be freed and full heap GC could be done later.
More on ART GC:
ART also introduced heap compaction which allows separate memory spaces released in previous GC triggers to be compacted into one continuous space (mo memory, less problems :p).
Prior to Android 8.0 this was done when application was in a stopped state by pausing threads but now happens in foreground itself with help of Concurrent Copying GC algorithm.
The runtime in it's current state has made sure that devs no longer need to invest time/resources on making their code performant and can focus more on what their consumer needs!
You can follow @_jitinsharma.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.