hn.today

Finding and fixing Android memory leaks with Perfetto, SQL, and AI agents

perfetto.dev26 points8 comments
Screenshot of Finding and fixing Android memory leaks with Perfetto, SQL, and AI agents

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.

Read on perfetto.dev8 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Laravel Go

Laravel Go

Laravel for Go is a full-stack web framework with routing, validation, database tools, background jobs, workflows, and real-time events. It also supports Inertia for frontend integration and is open source under the MIT license. (github.com)

Laravel Go

Laravel Go

Laravel Go is a batteries-included Go framework that combines routing, data access, authentication, queues, workflows, and other features in one package. It uses standard Go patterns and Inertia to serve React, Vue, or Svelte pages without separate API boilerplate. (laravel.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.