Mobile Development 23 min read

Understanding ART Garbage Collection in Android: Fundamentals, Mechanisms, and Performance Optimizations

This article introduces the fundamentals of Android Runtime (ART) garbage collection, covering its historical background, key milestones, core features such as RegionTLAB, read barriers, pause behavior, generational support, target heap size calculations, multiplier impact, GC trigger thresholds, Systrace analysis, and parameter tuning strategies.

Coolpad Technology Team
Coolpad Technology Team
Coolpad Technology Team
Understanding ART Garbage Collection in Android: Fundamentals, Mechanisms, and Performance Optimizations

The article begins with an overview of the GC series, explaining that it will lay the groundwork for a subsequent story‑driven case study and provide a concise introduction to the basic concepts of ART garbage collection (GC).

Outline : research purpose, ART GC origin, milestones (introduction of Concurrent Copying), important features, GC category classification, multiplier introduction, heap byte calculations, GC trigger threshold computation, Systrace perspective, and parameter modification strategies.

GC Birth Background : GC originated around 1960 at MIT with Lisp, where automatic memory reclamation became necessary; John McCarthy described the first GC algorithm.

Milestones (excerpt of code): 史前时代 Dalvik->ART的诞生(Android 4.4) -> ART发展(Android 5.0~7.0) -> Android 8.0 引入 Concurrent Copying -> Android 10 再次引入分代 These milestones highlight the evolution from Dalvik to ART and the introduction of concurrent copying and generational GC.

Important Features :

RegionTLAB – a thread‑local allocation buffer that enables bump‑pointer allocation without synchronization. Example code: CC enables use of a bump‑pointer allocator called RegionTLAB. This allocates a thread‑local allocation buffer (TLAB) to each app thread, which can then allocate objects by bumping the "top" pointer without any synchronization.

Read Barrier – allows concurrent heap compaction without pausing application threads. Example snippet: CC performs heap defragmentation by concurrently copying objects without pausing app threads. This is achieved with the help of a read‑barrier which intercepts reference reads from the heap, without any intervention from the app developer.

Single Pause – ART reduces stop‑the‑world pauses to a single small pause, unlike Dalvik which required multiple pauses.

Generational Support – from Android 10 onward, ART adds a young‑generation collector to improve throughput and reduce full‑GC frequency.

GC Type Classification (excerpt from art/runtime/gc/collector/gc_type.h ): enum GcType { kGcTypeNone, kGcTypeSticky, // frees only objects allocated since last GC kGcTypePartial, kGcTypeFull, kGcTypeMax, }; Sticky GC is a lightweight generational collection; Partial and Full GC perform more aggressive reclamation.

Target Heap Size Calculation – For non‑sticky GC the heap grows by: uint64_t delta = bytes_allocated * (1.0 / GetTargetHeapUtilization() - 1.0); grow_bytes = std::min(delta, max_free_); ... target_size = bytes_allocated + static_cast (grow_bytes * multiplier); next_gc_type_ = collector::kGcTypeSticky; For sticky GC the algorithm ensures the target does not exceed allocated bytes plus an adjusted max‑free value.

Multiplier Introduction : The foreground heap growth multiplier defaults to 2.0; when read‑barrier is enabled an extra 1.0 is added, yielding a default multiplier of 3 for foreground apps. This “space‑for‑time” trade‑off enlarges the heap to reduce GC frequency.

GC Trigger Threshold (concurrent_start_bytes_) – Calculated after each GC as: size_t remaining_bytes = std::min(bytes_allocated_during_gc, kMaxConcurrentRemainingBytes); remaining_bytes = std::max(remaining_bytes, kMinConcurrentRemainingBytes); concurrent_start_bytes_ = std::max(target_footprint - remaining_bytes, bytes_allocated); When a new allocation makes the total allocated bytes exceed this threshold, a concurrent GC is requested.

Systrace Perspective : Real‑world traces (e.g., TikTok startup) show heap growth during launch, a background concurrent copying GC that shrinks the heap, and subsequent foreground GC cycles. The trace phases are Initialize → Copying → Reclaim.

Parameter Modification Strategy : Parameters such as max_free_ , min_free_ , and target utilization are exposed as system properties. Increasing max_free_ enlarges the reserved free space, reducing GC frequency at the cost of higher memory usage.

Conclusion : Understanding ART GC mechanisms—especially the impact of multiplier, generational strategies, and trigger thresholds—provides a solid foundation for performance tuning and future optimizations.

References :

ART运行时Foreground GC和Background GC切换过程分 – https://www.kancloud.cn/alex_wsc/androids/472237

Android性能优化(31)---虚拟机调优 – https://blog.csdn.net/zhangbijun1230/article/details/79996702

ART虚拟机 | GC的触发时机和条件 – https://juejin.cn/post/6875678394332217357

performanceMemory ManagementAndroidartruntimeGarbage Collection
Coolpad Technology Team
Written by

Coolpad Technology Team

Committed to advancing technology and supporting innovators. The Coolpad Technology Team regularly shares forward‑looking insights, product updates, and tech news. Tech experts are welcome to join; everyone is invited to follow us.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.