Google Dianne Hackborn Jan 31, 2014

Process Stats: Understanding How Your App Uses Memory

Article Summary

Dianne Hackborn from the Android framework team reveals a hidden tool that exposes exactly how your app behaves when users aren't looking. Most developers are flying blind on background memory usage.

Android 4.4 KitKat introduced procstats, a system service that tracks app memory usage over time rather than just snapshots. This Google blog post explains why traditional task managers miss the real story and how procstats captures what's actually happening in the background.

Key Takeaways

Critical Insight

Procstats gives developers a time-based view of background memory consumption, revealing inefficiencies that snapshot tools like traditional task managers completely miss.

The article includes actual command line outputs showing how a Clock app used 3x more RAM than Google Keyboard despite running half the time.

About This Article

Problem

Developers couldn't see how apps actually behaved when running in the background. Task managers only showed memory snapshots at a single moment, which didn't capture what was really happening over time. This made it impossible to spot memory problems on low-RAM devices.

Solution

Google built the procstats service to watch all running processes continuously. It tracks how apps move between different states like Imp Fg, Imp Bg, Service, and Receiver modes, collecting memory samples throughout. This gives developers a real picture of how memory use changes over time.

Impact

With procstats, developers could finally measure background memory use accurately. They discovered the Clock app consumed almost 3x more RAM than Google Keyboard even though it ran less than half the time. This data directly helped Android 4.4's Project Svelte cut down memory usage.