Fix Memory Leak When Switching Input Methods
Fixes a memory leak when input methods are switched. Uses a variety of methods
to avoid holding a reference to the InputMethodService which created the binders,
which was leaking those InputMethodServices.
See http://code.google.com/p/android/issues/detail?id=6661 for reproduction steps.
diff --git a/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java b/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java
index 6cf90d6..7ee35c0 100644
--- a/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java
+++ b/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java
@@ -31,9 +31,10 @@
private static final int DO_UPDATE_CURSOR = 95;
private static final int DO_APP_PRIVATE_COMMAND = 100;
private static final int DO_TOGGLE_SOFT_INPUT = 105;
-
- final HandlerCaller mCaller;
- final InputMethodSession mInputMethodSession;
+ private static final int DO_FINISH_SESSION = 110;
+
+ HandlerCaller mCaller;
+ InputMethodSession mInputMethodSession;
// NOTE: we should have a cache of these.
static class InputMethodEventCallbackWrapper implements InputMethodSession.EventCallback {
@@ -111,6 +112,10 @@
mInputMethodSession.toggleSoftInput(msg.arg1, msg.arg2);
return;
}
+ case DO_FINISH_SESSION: {
+ mInputMethodSession = null;
+ return;
+ }
}
Log.w(TAG, "Unhandled message code: " + msg.what);
}
@@ -158,4 +163,8 @@
public void toggleSoftInput(int showFlags, int hideFlags) {
mCaller.executeOrSendMessage(mCaller.obtainMessageII(DO_TOGGLE_SOFT_INPUT, showFlags, hideFlags));
}
+
+ public void finishSession() {
+ mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_FINISH_SESSION));
+ }
}