android-memory-leak-fixer

Diagnose Android memory leaks by tracing retention paths and recommending lifecycle-aware fixes.

1|Updated Jun 27, 2026
One-click install
npx skills add https://github.com/TE-QuanBZhang/skills-pool --skill android-memory-leak-fixer-te-quanbzhang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-memory-leak-fixer
Source: https://github.com/TE-QuanBZhang/skills-pool/tree/main/ai-coding/skills/android-memory-leak-fixer
Command: npx skills add https://github.com/TE-QuanBZhang/skills-pool --skill android-memory-leak-fixer-te-quanbzhang

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Android apps often suffer from memory leaks and OOM crashes caused by retained Activities, Fragments, Views, listeners, and coroutines. This Skill provides a structured workflow to interpret LeakCanary reports, walk retention chains, classify the leak type, and recommend a fix that preserves behavior. ## Core Features & Use Cases - Retention Path Analysis: Trace strong reference chains to find the first suspicious owner, whether static, singleton, callback, coroutine, or observer. - Leak Classification: Categorize leaks into common buckets such as Fragment view binding leaks, adapter-held Activity references, unremoved listeners, and unbounded caches. - Fix and Validation Guidance: Recommend lifecycle-correct fixes (clearing bindings in onDestroyView, unregistering listeners, canceling screen-scoped jobs) plus LeakCanary recheck and memory profiler validation steps. - Use Case: You receive a LeakCanary report showing a retained Activity after repeated navigation. Use this Skill to walk the retention path, identify a singleton holding a Context reference, and get a fix with verification steps. ## Quick Start Analyze this LeakCanary report and the related source files to identify the leak owner and recommend a fix with validation steps.

Frequently Asked Questions about android-memory-leak-fixer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a memory leak reported by LeakCanary?

Start by identifying the retained object and walking its strong reference chain to find the first suspicious owner. Then classify the leak type, such as a Fragment binding leak or unremoved listener, and clear the reference at the correct lifecycle boundary.

How to find what is retaining an Activity in Android?

Trace the retention path from the LeakCanary report to locate static fields, singletons, callbacks, or coroutines holding the Activity. CodeGraph can help find all references to the leaked class, with rg or grep as a fallback.

Should I use WeakReference to fix Android memory leaks?

WeakReference should only be used when ownership is truly optional, not as a blanket solution. Prefer clearing references at the correct lifecycle boundary, removing listeners, and canceling screen-scoped jobs instead.

Why does my Fragment leak memory after navigation?

A common cause is keeping the view binding reference after onDestroyView, which retains the entire view hierarchy. Set the binding to null in onDestroyView and detach adapters or observers tied to the view lifecycle.

Can this skill help with OOM errors, not just leaks?

Yes, it also covers the OOM angle by inspecting bitmap decode sizes, unbounded cache growth, repeated object accumulation, and large bundles or intents. It recommends bounding caches and validating with memory profiler checks.