Android memory leaks often arise when object lifetimes fall out of sync: a callback, listener, or asynchronous task keeps a destroyed Fragment and its view hierarchy reachable, sometimes along with large bitmap or hardware buffers. Common patterns include callbacks registered on longer-lived Activity registries, listeners attached to window-level views, unbounded assets held by services, and cleanup coroutines cancelled before teardown runs. Memory growth can also come from unbounded executor queues or allocation-heavy reactive pipelines, even when objects are not permanently leaked. The recommended fixes are to bind registrations and listeners to the correct lifecycle, explicitly release heavy resources, ensure critical cleanup survives cancellation, bound queues, and reduce repeated intermediate allocations.
Perfetto provides a way to investigate these problems without changing app code. Its Java/Kotlin heap profiles capture object-retention graphs, named references, and allocation sizes without exporting strings or pixel data; native heap profiling and operating-system memory counters can be examined alongside them on a shared timeline. Developers can capture profiles with command-line tools, record them through the browser, or use Memscope to spot growing processes and collect snapshots. The workflow extends from visual heap and bitmap inspection to PerfettoSQL queries for local checks, CI automation, or analysis across many traces. An open-source AI skill can combine heap queries with code search and test generation to identify a retaining reference, propose a fix, and verify it.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.