From 1011779dfc6ea4a60e3ceb5c1947923404a2429d Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Wed, 12 Jul 2023 21:14:37 +0000 Subject: [PATCH] View: Remove tooltip callbacks when detached from window When a View has tooltip text set, every hover event will fire a callback to hide the tooltip after a 15 second timeout. Since the callback holds a reference to the View, it will leak the View for that duration after the Activity is finished or the View is removed. Prevent this temporary leak by removing the tooltip callbacks immediately when the View is detatched from the window. Bug: 281473769 Test: manual, heap dump using Android Studio Change-Id: I9044759be0feaf094aa4c140565dfa015b944bd8 --- core/java/android/view/View.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f1cde3b4bb7ea..2499be999f8df 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -21821,6 +21821,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mCurrentAnimation = null; if ((mViewFlags & TOOLTIP) == TOOLTIP) { + removeCallbacks(mTooltipInfo.mShowTooltipRunnable); + removeCallbacks(mTooltipInfo.mHideTooltipRunnable); hideTooltip(); }