SIGN IN SIGN UP
square / leakcanary UNCLAIMED

A memory leak detection library for Android.

0 0 74 Kotlin

Fix ToastEventListener race condition retaining finished Toast

showToastBlocking() blocks the heap dump thread (via CountDownLatch)
until onAnimationEnd fires, but only up to a 5-second timeout. If the
timeout fires before the animation completes, the heap dump proceeds and
HeapDump posts a cleanup runnable to the main thread. That cleanup runs
while toastCurrentlyShown is still null (animation not done yet), so it
is a no-op. Then onAnimationEnd fires and sets toastCurrentlyShown = toast
permanently — no subsequent event clears it, causing a memory leak.

The fix: set toastCurrentlyShown = toast immediately after toast.show(),
before starting the animation. The cleanup runnable then always sees a
non-null reference and cancels + nulls it correctly, regardless of
whether onAnimationEnd has fired yet.

The partial fix in ade42f792 (adding toastCurrentlyShown = null to the
cleanup) addressed the common case but not this timeout-driven race.

Fixes #2301
Fixes #2325

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
P
Pierre-Yves Ricau committed
9890f6931fb036534be5047a0c0b6d870934b484
Parent: f3f9207