Skip to content

Commit d5253fa

Browse files
author
Gilles Debunne
committed
All runnable are stopped on detach. DO NOT MERGE.
This prevents these runnable from holding a reference to the context that will prevent it from being garbage collected. The blinking cursor is especially bad and appears in memore traces. Change-Id: I8acbfbbfc59975dfd7bcf06e941074ea7dc0b0bc
1 parent ca36d86 commit d5253fa

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

core/java/android/widget/TextView.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3810,6 +3810,18 @@ protected void onDetachedFromWindow() {
38103810
hideError();
38113811
}
38123812

3813+
if (mBlink != null) {
3814+
mBlink.cancel();
3815+
}
3816+
3817+
if (mInsertionPointCursorController != null) {
3818+
mInsertionPointCursorController.onDetached();
3819+
}
3820+
3821+
if (mSelectionModifierCursorController != null) {
3822+
mSelectionModifierCursorController.onDetached();
3823+
}
3824+
38133825
hideControllers();
38143826
}
38153827

@@ -7720,6 +7732,13 @@ private interface CursorController extends ViewTreeObserver.OnTouchModeChangeLis
77207732
* @param event The touch event
77217733
*/
77227734
public boolean onTouchEvent(MotionEvent event);
7735+
7736+
/**
7737+
* Called when the view is detached from window. Perform house keeping task, such as
7738+
* stopping Runnable thread that would otherwise keep a reference on the context, thus
7739+
* preventing the activity to be recycled.
7740+
*/
7741+
public void onDetached();
77237742
}
77247743

77257744
private class HandleView extends View {
@@ -7997,12 +8016,12 @@ public void show() {
79978016

79988017
public void hide() {
79998018
mHandle.hide();
8000-
TextView.this.removeCallbacks(mHider);
8019+
removeCallbacks(mHider);
80018020
}
80028021

80038022
private void hideDelayed(int msec) {
8004-
TextView.this.removeCallbacks(mHider);
8005-
TextView.this.postDelayed(mHider, msec);
8023+
removeCallbacks(mHider);
8024+
postDelayed(mHider, msec);
80068025
}
80078026

80088027
public boolean isShowing() {
@@ -8042,6 +8061,11 @@ public void onTouchModeChanged(boolean isInTouchMode) {
80428061
hide();
80438062
}
80448063
}
8064+
8065+
@Override
8066+
public void onDetached() {
8067+
removeCallbacks(mHider);
8068+
}
80458069
}
80468070

80478071
private class SelectionModifierCursorController implements CursorController {
@@ -8219,6 +8243,11 @@ public void onTouchModeChanged(boolean isInTouchMode) {
82198243
hide();
82208244
}
82218245
}
8246+
8247+
@Override
8248+
public void onDetached() {
8249+
removeCallbacks(mHider);
8250+
}
82228251
}
82238252

82248253
private void hideInsertionPointCursorController() {

0 commit comments

Comments
 (0)