# leakcanary

LeakCanary is a memory leak detection library for Android.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Your favorite agents are now integrated in Android Studio

DevFeed: [Your favorite agents are now integrated in Android Studio](<https://devfeed.tech/articles/your-favorite-agents-are-now-integrated-in-android-studio-105738.md>)

Original publisher: [Read original article](<https://developer.android.com/blog/posts/ai-agents-android-studio-integration>)

Author: Matthew Warner

Published: 2026-10-28T00:00:00Z

Content type: release

Language: en

Sources: [Android Developers](<https://devfeed.tech/sources/android-developers-blog.md>)

Topics: [Android Studio](<https://devfeed.tech/topics/android-studio.md>), [AI-assisted coding](<https://devfeed.tech/topics/ai-assisted-coding.md>), [Agent Skills](<https://devfeed.tech/topics/agent-skills.md>), [Android](<https://devfeed.tech/topics/android.md>), [Android XR](<https://devfeed.tech/topics/android-xr.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [codex](<https://devfeed.tech/topics/codex.md>), [google-antigravity](<https://devfeed.tech/topics/google-antigravity.md>), [Large Screen](<https://devfeed.tech/topics/large-screen.md>), [cameraX](<https://devfeed.tech/topics/camerax.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [agent](<https://devfeed.tech/tags/agent.md>), [agent-skills](<https://devfeed.tech/tags/agent-skills.md>), [agents](<https://devfeed.tech/tags/agents.md>), [ai](<https://devfeed.tech/tags/ai.md>), [ai-code](<https://devfeed.tech/tags/ai-code.md>), [ai-code-review](<https://devfeed.tech/tags/ai-code-review.md>), [android](<https://devfeed.tech/tags/android.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [code](<https://devfeed.tech/tags/code.md>), [code-review](<https://devfeed.tech/tags/code-review.md>), [development](<https://devfeed.tech/tags/development.md>), [emulator](<https://devfeed.tech/tags/emulator.md>), [features](<https://devfeed.tech/tags/features.md>), [key](<https://devfeed.tech/tags/key.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [manager](<https://devfeed.tech/tags/manager.md>), [product-news](<https://devfeed.tech/tags/product-news.md>), [production](<https://devfeed.tech/tags/production.md>), [rabbit](<https://devfeed.tech/tags/rabbit.md>), [studio](<https://devfeed.tech/tags/studio.md>)

### AI overview

Android Studio Rabbit 2 is stable and lets developers use over 40 coding agents through Bring Your Own Agent, with access to Android Studio tools and Android skills. The release also makes XR emulators stable, including customizable display glasses environments and improved virtual-device pairing; adds a skills manager for discovering and managing Android and Firebase workflows; and integrates LeakCanary with the built-in agent to explain memory leaks and suggest code changes. Change Review identifies recommended fixes in agent changes and commits, then groups related diffs into a guided walkthrough. Gemini Enterprise support, available since Rabbit 1, offers internal knowledge integrations and enterprise controls for privacy, audit logging, and administrator policies. The excerpt does not detail every release feature.

### Source excerpt

Android Studio Rabbit 2 is now stable and ready for you to use in production. This release includes key features to improve your development such as Bring Your Own Agent, new XR Emulator features, a LeakCanary update, a new agent skills manager tool, AI code review, and more.

## Cutting some Slack, for leaks and giggles

DevFeed: [Cutting some Slack, for leaks and giggles](<https://devfeed.tech/articles/cutting-some-slack-for-leaks-and-giggles-25621.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/cutting-some-slack-for-leaks-and-giggles>)

Author: Pierre-Yves Ricau

Published: 2024-05-07T00:47:25Z

Content type: article

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [UiAutomator](<https://devfeed.tech/topics/uiautomator.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [emulator](<https://devfeed.tech/tags/emulator.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [growth](<https://devfeed.tech/tags/growth.md>), [heap](<https://devfeed.tech/tags/heap.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [maestro](<https://devfeed.tech/tags/maestro.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [performance](<https://devfeed.tech/tags/performance.md>), [slack](<https://devfeed.tech/tags/slack.md>)

### AI overview

LeakCanary 3.0 alpha 4 adds a heap-growth detector for cases where memory use keeps rising without a reported leak, such as a collection that continually accumulates log strings. It compares repeated heap dumps and looks for objects whose outgoing edges keep increasing. The author runs it as a UI Automator test that switches between Slack Android workspaces. On normal Android OS builds, dumping another app's heap requires that app to be debuggable or profileable as shell; the author says those restrictions do not apply on non-Play-Store emulator images. The excerpt ends before reporting the experiment's findings.

### Source excerpt

In this article I run the new LeakCanary toolkit against the Slack Android app. Read on to learn a bunch! A new LeakCanary toolkit In two months, I will give a talk at Droidcon SF: Cutting Edges: universal heap trimming with LeakCanary 3 At Square, ...

## Avoid Java double brace initialization

DevFeed: [Avoid Java double brace initialization](<https://devfeed.tech/articles/avoid-java-double-brace-initialization-25619.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/avoid-java-double-brace-initialization>)

Author: Pierre-Yves Ricau

Published: 2023-06-27T20:58:00Z

Content type: article

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [hashmap](<https://devfeed.tech/tags/hashmap.md>), [java](<https://devfeed.tech/tags/java.md>), [leak](<https://devfeed.tech/tags/leak.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [patterns](<https://devfeed.tech/tags/patterns.md>)

### AI overview

A BugSnag breadcrumb's metadata map kept a destroyed Activity in memory because it was created with Java double brace initialization. That pattern makes an anonymous HashMap subclass whose implicit reference to its enclosing Activity survives through the breadcrumb. The excerpt recommends avoiding the pattern and initializing the map directly, using a helper for cleaner code, or converting the file to Kotlin. The leak trace also distinguishes the intentionally long-lived BugSnag singleton and breadcrumb ring buffer from the unexpectedly retained Activity.

### Source excerpt

TL;DR Avoid doing this: new HashMap() {{ put("key", value); }}; Leak Trace I was recently looking at the following leak trace from LeakCanary: ┬─── │ GC Root: Global variable in native code │ ├─ com.bugsnag.android.AnrPlugin instan...

## Callback leaks: cancel your Picasso requests!

DevFeed: [Callback leaks: cancel your Picasso requests!](<https://devfeed.tech/articles/callback-leaks-cancel-your-picasso-requests-25620.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/callback-leaks-cancel-your-picasso-requests>)

Author: Pierre-Yves Ricau

Published: 2023-01-17T21:06:14Z

Content type: article

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [Picasso](<https://devfeed.tech/topics/picasso.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [callback](<https://devfeed.tech/topics/callback.md>)

Tags: [actions](<https://devfeed.tech/tags/actions.md>), [adapter](<https://devfeed.tech/tags/adapter.md>), [also](<https://devfeed.tech/tags/also.md>), [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [android-engineer](<https://devfeed.tech/tags/android-engineer.md>), [article](<https://devfeed.tech/tags/article.md>), [block](<https://devfeed.tech/tags/block.md>), [callback](<https://devfeed.tech/tags/callback.md>), [engineer](<https://devfeed.tech/tags/engineer.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [i](<https://devfeed.tech/tags/i.md>), [leak](<https://devfeed.tech/tags/leak.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [learn](<https://devfeed.tech/tags/learn.md>), [look](<https://devfeed.tech/tags/look.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [performance](<https://devfeed.tech/tags/performance.md>), [picasso](<https://devfeed.tech/tags/picasso.md>), [this](<https://devfeed.tech/tags/this.md>), [top](<https://devfeed.tech/tags/top.md>), [work](<https://devfeed.tech/tags/work.md>)

### AI overview

A Picasso request can keep a detached UI component from being garbage collected when its custom callback captures the component and the request remains in flight. Picasso's singleton holds weak references to target views but strong references to actions; the action and callback can therefore retain the detached view. Cancel requests when the UI goes away to prevent the leak and avoid continued resource use while loading. The excerpt also says Picasso automatically cancels a previous request when a new image is loaded into the same ImageView, which helps with recycled adapter views. It cuts off during that explanation, so it does not establish the full set of circumstances in which leaks are avoided.

### Source excerpt

👋 Hi, this is P.Y., I work as an Android Engineer at Block. Every month I organize an internal Ensemble Leak Hunting session where we look at the top leaks reported by LeakCanary to learn how to read

## ViewLifecycleLazy and other ways to avoid View memory leaks in Android Fragments

DevFeed: [ViewLifecycleLazy and other ways to avoid View memory leaks in Android Fragments](<https://devfeed.tech/articles/viewlifecyclelazy-and-other-ways-to-avoid-view-memory-leaks-in-android-fragments-25885.md>)

Original publisher: [Read original article](<https://bladecoder.medium.com/viewlifecyclelazy-and-other-ways-to-avoid-view-memory-leaks-in-android-fragments-4aa982e6e579?source=rss-54910f05af37------2>)

Author: Christophe Beyls

Published: 2022-09-28T06:12:25Z

Content type: article

Language: en

Sources: [Christophe Beyls](<https://devfeed.tech/sources/stories-by-christophe-beyls-on-medium.md>)

Topics: [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [canary](<https://devfeed.tech/tags/canary.md>), [compose](<https://devfeed.tech/tags/compose.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [view](<https://devfeed.tech/tags/view.md>), [view-binding](<https://devfeed.tech/tags/view-binding.md>)

### AI overview

Fragment view references must be cleared in `onDestroyView()` to avoid memory leaks. `ViewLifecycleLazy` is a Kotlin delegate that initializes its value lazily and clears it when the Fragment's view lifecycle reaches `DESTROYED`; accessing it when no view hierarchy is available throws through `requireView()` or `viewLifecycleOwner`. The article says this approach avoids the extra observer setup of `AutoClearedValue` and, by implementing `Lazy`, avoids per-property `KProperty` metadata, though it notes this may not strictly follow the `Lazy` contract. Prefer keeping view references local to `onViewCreated()`, passing them to helper functions, and updating views through lifecycle-aware callbacks. Use the delegate for cases where that pattern is impractical, and read it only while the Fragment has a view hierarchy.

### Source excerpt

Yet another take on AutoClearedValueAre your Fragments leaking? Handling the lifecycle of Android Fragments is difficult. I already covered this topic in an article I wrote in 2017, before Google added a View-specific Lifecycle to Fragments in an attempt to solve some issues. Until now, the number one cause of memory leaks when using Fragments remains the same: not properly clearing all direct and indirect View references in onDestroyView(). Tools like Leak Canary can help detecting some of these cases. And of course, Jetpack Compose represents a big paradigm change which completely removes the need to keep View references but hey, we still have our legacy codebases to maintain! I recently came across a Medium blog post from Gabor Varadi describing an issue he encountered with a custom Kotlin delegated property he created to simplify managing view bindings in Fragments. His solution is based on a class named AutoClearedValue from the architecture components samples. The purpose of AutoClearedValue is to provide a delegate that will automatically clear a value tied to one or more Views when the Fragment View hierarchy gets destroyed, in order to avoid the aforementioned memory leaks. This is an elegant alternative to declaring a Fragment property as nullable and manually setting it to null in onDestroyView(), which can be easily forgotten. It turns out I had already come up with my own solution to do the exact same thing. And since my version is simpler and generates more optimized bytecode compared to AutoClearedValue and what Mr Varadi published, I decided to share it with you. I named this delegate ViewLifecycleLazy. Like the name implies, the delegated property value is computed lazily and the Fragment's current view lifecycle is observed in order to automatically clear the value when it moves to the DESTROYED state. https://medium.com/media/17c61e41a0f2d3e17c63e3bcf8f6376c/href This is how it's used in Fragments, for example with View Binding: class MyFragment :

## WhileSubscribed(5000)

DevFeed: [WhileSubscribed(5000)](<https://devfeed.tech/articles/whilesubscribed-5000-25635.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/whilesubscribed5000>)

Author: Pierre-Yves Ricau

Published: 2022-08-30T23:01:56Z

Content type: article

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [now-in-android](<https://devfeed.tech/topics/now-in-android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-apps](<https://devfeed.tech/tags/android-apps.md>), [android-engineer](<https://devfeed.tech/tags/android-engineer.md>), [app](<https://devfeed.tech/tags/app.md>), [block](<https://devfeed.tech/tags/block.md>), [compose](<https://devfeed.tech/tags/compose.md>), [config](<https://devfeed.tech/tags/config.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [delay](<https://devfeed.tech/tags/delay.md>), [flow](<https://devfeed.tech/tags/flow.md>), [fragment](<https://devfeed.tech/tags/fragment.md>), [gabor-varadi](<https://devfeed.tech/tags/gabor-varadi.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [now-in-android](<https://devfeed.tech/tags/now-in-android.md>), [operators](<https://devfeed.tech/tags/operators.md>), [scope](<https://devfeed.tech/tags/scope.md>), [stream](<https://devfeed.tech/tags/stream.md>), [twitter](<https://devfeed.tech/tags/twitter.md>)

### AI overview

The 5-second WhileSubscribed timeout keeps an upstream flow active briefly after its last collector disappears, which can avoid restarting it during an activity configuration change. Without the delay, rotation can drop the subscription count to zero, stop sharing, then restart the upstream flow on resume; the cached state value is reused. The author objects to treating this delay as a default for every ViewModel flow. Eagerly starting sharing avoids that restart, but keeps the upstream flow active for the ViewModel's lifetime, typically tied to an Activity or Fragment. The excerpt does not describe further limitations or alternatives.

### Source excerpt

👋 Hi, this is P.Y., I work as an Android Engineer at Block. I know nothing about Compose so please let me know if I messed up on Twitter! I've been hacking on a new LeakCanary standalone app to visua

## Announcing Shark: Smart Heap Analysis Reports for Kotlin

DevFeed: [Announcing Shark: Smart Heap Analysis Reports for Kotlin](<https://devfeed.tech/articles/announcing-shark-smart-heap-analysis-reports-for-kotlin-15513.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/announcing-shark-smart-heap-analysis-reports-for-kotlin>)

Author: P-Y Ricau

Published: 2019-08-06T19:00:00Z

Content type: release

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [2015](<https://devfeed.tech/tags/2015.md>), [3](<https://devfeed.tech/tags/3.md>), [all](<https://devfeed.tech/tags/all.md>), [also](<https://devfeed.tech/tags/also.md>), [analysis](<https://devfeed.tech/tags/analysis.md>), [analyze](<https://devfeed.tech/tags/analyze.md>), [android](<https://devfeed.tech/tags/android.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [android-vm](<https://devfeed.tech/tags/android-vm.md>), [app](<https://devfeed.tech/tags/app.md>), [apps](<https://devfeed.tech/tags/apps.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [automatically](<https://devfeed.tech/tags/automatically.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [heap](<https://devfeed.tech/tags/heap.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [powers](<https://devfeed.tech/tags/powers.md>), [reports](<https://devfeed.tech/tags/reports.md>), [smart](<https://devfeed.tech/tags/smart.md>)

### AI overview

Shark is a standalone Kotlin heap analyzer that powers LeakCanary 2. It scans an HPROF file once to index object locations, then reads objects on demand; extra index metadata and an LRU cache reduce I/O. The article reports that LeakCanary found shortest paths from GC Roots to leaking objects six times faster than with perflib while using one tenth the memory. Shark is layered from HPROF record reading and graph navigation through report generation, Android heuristics, and a CLI; LeakCanary builds on it to watch destroyed activities and fragments, trigger heap dumps, and display analysis. The CLI can dump and analyze heaps from debuggable apps on a connected Android device, analyze HPROF files, and replace primitive arrays with zeroes to help remove sensitive data. Shark runs on Java and Android VMs and depends on Okio and Kotlin.

### Source excerpt

The heap analyzer that powers LeakCanary 2

## Story of an Android Q Leak: attachment crazy town!

DevFeed: [Story of an Android Q Leak: attachment crazy town!](<https://devfeed.tech/articles/story-of-an-android-q-leak-attachment-crazy-town-15896.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/story-of-an-android-q-leak-attachment-crazy-town>)

Author: P-Y Ricau

Published: 2019-07-03T19:00:00Z

Content type: article

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [Android](<https://devfeed.tech/topics/android.md>), [adb](<https://devfeed.tech/topics/adb.md>)

Tags: [accessibility](<https://devfeed.tech/tags/accessibility.md>), [android](<https://devfeed.tech/tags/android.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [leak](<https://devfeed.tech/tags/leak.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [pos](<https://devfeed.tech/tags/pos.md>), [square](<https://devfeed.tech/tags/square.md>)

### AI overview

Square POS saw Android Q leaks because a view could be detached and then attached out of order when its parent synchronously removed it during onAttachedToWindow(). The app's JailView did this while wiring up a presenter; ViewGroup continued attaching its children after the detach, leaving them registered in the framework's AccessibilityNodeIdManager and retained. The author describes reproducing the sequence with a FrameLayout and Button. They say Android Q would use weak references in a future release, while Square was migrating from its MVP architecture to Workflow, which does not rely on onAttachedToWindow().

### Source excerpt

Debugging leaks for Square POS in Android Q

## Streamlining Android Apps Tech Talks

DevFeed: [Streamlining Android Apps Tech Talks](<https://devfeed.tech/articles/streamlining-android-apps-tech-talks-15897.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/streamlining-android-apps-tech-talks>)

Author: Square Engineering

Published: 2015-08-24T16:09:00Z

Content type: news

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-apps](<https://devfeed.tech/tags/android-apps.md>), [code](<https://devfeed.tech/tags/code.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [overhead](<https://devfeed.tech/tags/overhead.md>), [presentations](<https://devfeed.tech/tags/presentations.md>), [talks](<https://devfeed.tech/tags/talks.md>), [tech](<https://devfeed.tech/tags/tech.md>)

### AI overview

Jake Wharton and PY gave tech talks at Square's "Streamlining Android Apps" event in San Francisco. The talks covered eliminating code overhead and LeakCanary, and recordings are available on Square Engineering's YouTube channel. The excerpt gives no further details about the presentations.

### Source excerpt

Presentations on eliminating code overhead and LeakCanary.

## A small leak will sink a great ship

DevFeed: [A small leak will sink a great ship](<https://devfeed.tech/articles/a-small-leak-will-sink-a-great-ship-15476.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/a-small-leak-will-sink-a-great-ship>)

Author: P-Y Ricau

Published: 2015-08-20T16:09:00Z

Content type: article

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [Android Testing](<https://devfeed.tech/topics/android-testing.md>)

Tags: [alert](<https://devfeed.tech/tags/alert.md>), [android](<https://devfeed.tech/tags/android.md>), [android-apps](<https://devfeed.tech/tags/android-apps.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [leak](<https://devfeed.tech/tags/leak.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>)

### AI overview

On pre-Lollipop Android running Dalvik, a worker thread can retain its last message in a stack local while blocked, even after that message is no longer logically in use. AlertDialog button setup can leave its original message holding an OnClickListener, which may capture an Activity; if a recycled message is later retained by a worker thread, that reference chain can keep the destroyed Activity and its view hierarchy alive. The article reports reproductions on Dalvik, not ART or a JVM. Suggested mitigations are to clear dialog listener references when the window detaches, periodically flush idle HandlerThreads, or support only ART devices, with the last option sacrificing older-device users. LeakCanary ignores Message leaks by default; the article notes that a retained Activity can still consume several megabytes.

### Source excerpt

Prior to Android Lollipop, alert dialogs may cause memory leaks in your Android apps.

## LeakCanary: Detect all memory leaks!

DevFeed: [LeakCanary: Detect all memory leaks!](<https://devfeed.tech/articles/leakcanary-detect-all-memory-leaks-15743.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/leakcanary-detect-all-memory-leaks>)

Author: P-Y Ricau

Published: 2015-05-08T16:08:00Z

Content type: article

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [detection](<https://devfeed.tech/tags/detection.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [java](<https://devfeed.tech/tags/java.md>), [leak](<https://devfeed.tech/tags/leak.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [library](<https://devfeed.tech/tags/library.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>)

### AI overview

LeakCanary detects Java memory leaks in Android debug builds before they accumulate into out-of-memory crashes. A leak occurs when references keep an object alive beyond its expected lifetime; the article's example is a background thread retaining a destroyed Activity. LeakCanary can watch an object and report the strong reference path from a GC root to the leaked instance, and a single `LeakCanary.install(this)` call enables automatic Activity leak detection with notifications and a display. The article contrasts this automated detection with manual investigation: reproduce the crash, dump the heap, inspect it in MAT or YourKit, trace references to GC roots, and remove the unwanted reference. It reports 94% fewer OOM crashes after the authors used LeakCanary to find and fix leaks in their app, including some in the Android SDK; this is their reported result, not a general guarantee.

### Source excerpt

A memory leak detection library for Android and Java.