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/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index e2e0ba9..afcba47 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -855,12 +855,26 @@
}
}
+ private void finishSession(SessionState sessionState) {
+ if (sessionState != null && sessionState.session != null) {
+ try {
+ sessionState.session.finishSession();
+ } catch (RemoteException e) {
+ Log.w(TAG, "Session failed to close due to remote exception", e);
+ }
+ }
+ }
+
void clearCurMethodLocked() {
if (mCurMethod != null) {
for (ClientState cs : mClients.values()) {
cs.sessionRequested = false;
+ finishSession(cs.curSession);
cs.curSession = null;
}
+
+ finishSession(mEnabledSession);
+ mEnabledSession = null;
mCurMethod = null;
}
mStatusBar.setIconVisibility(mInputMethodIcon, false);