memory-leak-hunter

Diagnose Android memory leaks from LeakCanary traces and heap dumps.

Updated Jan 2, 2024
One-click install
npx skills add https://github.com/Mithrandir21/game-deals-app --skill memory-leak-hunter-mithrandir21
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: memory-leak-hunter
Source: https://github.com/Mithrandir21/game-deals-app/tree/main/.claude/skills/memory-leak-hunter
Command: npx skills add https://github.com/Mithrandir21/game-deals-app --skill memory-leak-hunter-mithrandir21

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Android memory leaks from unregistered listeners, static references, retained Compose state, and runaway coroutines cause OOM crashes and degraded performance, but LeakCanary traces and heap dumps are hard to interpret without a systematic triage process. ## Core Features & Use Cases - Leak Trace Analysis: Reads LeakCanary reference chains from GC root to leaked object to pinpoint the first breakable reference. - Leak Shape Classification: Matches evidence against eight common leak patterns including listener leaks, static context holds, inner-class captures, Handler callbacks, coroutine scope leaks, Compose remember leaks, drawable callbacks, and unbounded Bitmap caches. - False Positive Filtering: Distinguishes real leaks from intentional retention like NavGraph-scoped ViewModels and applicationContext singletons. - Use Case: A developer sees a LeakCanary notification for a leaked Fragment after rotation, pastes the trace, and receives the leak shape, the exact fix (unregister in onDestroyView), and a guardrail test suggestion. ## Quick Start Analyze this LeakCanary trace showing a leaked MainActivity and tell me the leak shape, the fix, and how to prevent it from recurring.

Frequently Asked Questions about memory-leak-hunter

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

FAQPage Schema
How do I read a LeakCanary leak trace?▼

Read the chain from the GC root at the top down to the leaked object at the bottom. The first reference you can break in that chain is where you apply the fix, such as unregistering a listener or clearing a static reference.

How to fix a leaked Activity or Fragment in Android?▼

Identify what long-lived object holds the reference, then match it to a common shape: unregister listeners in onStop or onDestroyView, avoid static Context fields, use static inner classes or WeakReference, and cancel pending Handler callbacks.

Can Jetpack Compose cause memory leaks?▼

Yes. A remember block holding an object that captures an Activity can outlive the composition. Hoist the object into a ViewModel or use DisposableEffect to release it when the composable leaves the composition.

Why does LeakCanary report leaks that are not real?▼

Retained Fragments and NavGraph-scoped ViewModels survive configuration changes intentionally, and an Activity may simply not be garbage collected yet. Force a GC in the profiler and re-check before concluding a leak exists.

Do coroutines cause memory leaks in Android?▼

Coroutines leak when launched in GlobalScope or a custom scope that is never cancelled, or when a ViewModel coroutine references a View. Use viewModelScope or lifecycleScope so cancellation follows the lifecycle automatically.

When is an OutOfMemoryError not a memory leak?▼

An OOM caused by decoding one huge bitmap is an image sizing problem, not a leak. Fix it by downsampling the image or using an image loader rather than hunting for retained references.