Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d552a523 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add a comment about ResultReceiver lifetime.

The root cause of memory leak crbug.com/595613 was that Chromium and
WebView have called InputMethodManager#showSoftInput() with
ResultReceiver thta has a strong reference to application logic class
named ContentViewCore.  In this particular case, ResultReceiver in
question will be copied to InputMethodManagerService and the current
InputMethodService, which means the original receiver object will not be
collected until the copied objects in other processes are GCed.

Probably there might be several ways to oprimize the performance in
Framework side because the corresponding ResultReceiver objects will be
always handled within the Android Framework unless IME developers
explicitly override the following method.
  InputMethodService#onCreateInputMethodInterface()

Anyway, it is probably a bit too late to do such an optimization in N,
and application developers need to support existing versions of Android
anyway.  For N, probably making it clear in JavaDoc would be the only
realistic improvement we can do.

Bug: 27658034
Bug: 27727645
Change-Id: I6fc6b88c91a4b1e0a29e94b99a9f0e35605c01b2
parent c1d317f7
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -976,6 +976,16 @@ public final class InputMethodManager {
     * your view in such a way that they have expressed they would like to
     * start performing input into it.
     *
     * <p><strong>Caveat:</strong> {@link ResultReceiver} instance passed to
     * this method can be a long-lived object, because it may not be
     * garbage-collected until all the corresponding {@link ResultReceiver}
     * objects transferred to different processes get garbage-collected.
     * Follow the general patterns to avoid memory leaks in Android.
     * Consider to use {@link java.lang.ref.WeakReference} so that application
     * logic objects such as {@link android.app.Activity} and {@link Context}
     * can be garbage collected regardless of the lifetime of
     * {@link ResultReceiver}.
     *
     * @param view The currently focused view, which would like to receive
     * soft keyboard input.
     * @param flags Provides additional operating flags.  Currently may be
@@ -1045,6 +1055,16 @@ public final class InputMethodManager {
     * of the user doing some actually than fairly explicitly requests to
     * have the input window hidden.
     *
     * <p><strong>Caveat:</strong> {@link ResultReceiver} instance passed to
     * this method can be a long-lived object, because it may not be
     * garbage-collected until all the corresponding {@link ResultReceiver}
     * objects transferred to different processes get garbage-collected.
     * Follow the general patterns to avoid memory leaks in Android.
     * Consider to use {@link java.lang.ref.WeakReference} so that application
     * logic objects such as {@link android.app.Activity} and {@link Context}
     * can be garbage collected regardless of the lifetime of
     * {@link ResultReceiver}.
     *
     * @param windowToken The token of the window that is making the request,
     * as returned by {@link View#getWindowToken() View.getWindowToken()}.
     * @param flags Provides additional operating flags.  Currently may be