New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 595613 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner:
Closed: Mar 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 1
Type: Bug



Sign in to add a comment

memory leak from showSoftInput

Project Member Reported by changwan@chromium.org, Mar 17 2016

Issue description

When calling showSoftInput() with a ResultReceiver object, the object is held by the Android framework and doesn't get released.

The result is that WebView object does not get released even when the view gets removed.

The reason behind having ResultReceiver is as follows:
- OSK triggers resize of the viewport
- if we scroll to the input form at the same time viewport resizes, flickering can happen
- therefore, we delay scrolling until viewport resize completes

Originally filed as b/27658034

 
One idea to fix this is to wait until issue 404315 is resolved, and then remove ResultReceiver and scrolls to the input form immediately after showSoftInput()
(or focusedNodeChanged could be another option)
Blockedon: 404315
BTW, this logic was originally introduced a long time ago:
https://chromiumcodereview.appspot.com/10911012/
https://chromiumcodereview.appspot.com/11081003/

Actually, the rationale for delayed scrolling was completely my assumption.
I just did some testing and could not find such a flickering issue.

Alex, do you know why it was added 4 years ago? Do you think we can safely remove the delay logic without waiting for issue 404315?

Blockedon: -404315
Ok, I did a bit more testing and found that scrolling logic does not work correctly when input form is at the bottom and going to be hidden by input method window. We should apply the scrolling logic only after input method window shows up on the screen. This is regardless of issue 404315.

I'll try to find a way to weakreference inside ResultReceiver instead.

Comment 6 by aelias@chromium.org, Mar 17 2016

Cc: ymalik@chromium.org torne@chromium.org
Is this issue severe enough that we want to cherry-pick the workaround to M50?  If for M51 only, we might have more options that can take advantage of ymalik@'s just landed patch https://codereview.chromium.org/1386403003/.

> Ok, I did a bit more testing and found that scrolling logic does not work correctly when input form is at the bottom and going to be hidden by input method window.

Right, but this is a problem we saw in Chrome.  I'm not sure whether the delaying actually does anything useful for WebView, which has very different viewporting environment.  It's possible we could simply strip out the logic for WebView with no ill effect.

Comment 7 by boliu@chromium.org, Mar 17 2016

Labels: ReleaseBlock-Stable M-50
So from b/27658034, weak reference is the right solution. This looks severe enough to warrant merging back to m50 at least.
Re #6, as bo said, this seems like a severe problem even though it is not a recent regression. I'll take the weak-reference approach for now, but hopefully we wouldn't need the logic in the near future.
Project Member

Comment 9 by bugdroid1@chromium.org, Mar 18 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fcc3fbf1652285b2a89eabd092d35d0fdf199ac2

commit fcc3fbf1652285b2a89eabd092d35d0fdf199ac2
Author: changwan <changwan@chromium.org>
Date: Fri Mar 18 04:55:47 2016

Fix webview memory leak when keyboard was shown

Android framework does not seem to release ResultReceiver passed in
InputMethodManager#showSoftInput() after use. As a result, WebView
will not be garbage collected after it's removed, if keyboard shows up
on the screen once.

ResultReceiver cannot be avoided since we want to scroll to the editable
node only after input method window shows up.

This is a fix to weak-reference CVC object (and thus WebView as well) from
ResultReceiver. Unfortunately, ResultReceiver will still be leaked,
but the leak can be significantly reduced.

A test is added to AwContentsGarbageCollectionTest to test that references
to WebView can be removed even when showSoftInput() is called before
garbage collection.

Also, I've manually tested that the new test can catch the memory leak
issue when we strong-reference CVC.

BUG= 595613 

Review URL: https://codereview.chromium.org/1809013002

Cr-Commit-Position: refs/heads/master@{#381891}

[modify] https://crrev.com/fcc3fbf1652285b2a89eabd092d35d0fdf199ac2/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java
[modify] https://crrev.com/fcc3fbf1652285b2a89eabd092d35d0fdf199ac2/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Labels: Merge-Request-50
requesting merge of #9 to m50

Comment 11 by tin...@google.com, Mar 18 2016

Labels: -Merge-Request-50 Merge-Approved-50 Hotlist-Merge-Approved
Your change meets the bar and is auto-approved for M50 (branch: 2661)
Project Member

Comment 12 by bugdroid1@chromium.org, Mar 18 2016

Labels: -merge-approved-50 merge-merged-2661
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/03b18f07ad4cee19f59d9a494a9c7f354a2a09b6

commit 03b18f07ad4cee19f59d9a494a9c7f354a2a09b6
Author: Changwan Ryu <changwan@google.com>
Date: Fri Mar 18 05:34:31 2016

Fix webview memory leak when keyboard was shown

Android framework does not seem to release ResultReceiver passed in
InputMethodManager#showSoftInput() after use. As a result, WebView
will not be garbage collected after it's removed, if keyboard shows up
on the screen once.

ResultReceiver cannot be avoided since we want to scroll to the editable
node only after input method window shows up.

This is a fix to weak-reference CVC object (and thus WebView as well) from
ResultReceiver. Unfortunately, ResultReceiver will still be leaked,
but the leak can be significantly reduced.

A test is added to AwContentsGarbageCollectionTest to test that references
to WebView can be removed even when showSoftInput() is called before
garbage collection.

Also, I've manually tested that the new test can catch the memory leak
issue when we strong-reference CVC.

BUG= 595613 

Review URL: https://codereview.chromium.org/1809013002

Cr-Commit-Position: refs/heads/master@{#381891}
(cherry picked from commit fcc3fbf1652285b2a89eabd092d35d0fdf199ac2)

Review URL: https://codereview.chromium.org/1810273002 .

Cr-Commit-Position: refs/branch-heads/2661@{#281}
Cr-Branched-From: ef6f6ae5e4c96622286b563658d5cd62a6cf1197-refs/heads/master@{#378081}

[modify] https://crrev.com/03b18f07ad4cee19f59d9a494a9c7f354a2a09b6/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java
[modify] https://crrev.com/03b18f07ad4cee19f59d9a494a9c7f354a2a09b6/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Status: Fixed (was: Assigned)
Project Member

Comment 14 by bugdroid1@chromium.org, Mar 18 2016

Project Member

Comment 15 by bugdroid1@chromium.org, Mar 28 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fccdae63cab073c8076d42edf15c4a8424a33a2c

commit fccdae63cab073c8076d42edf15c4a8424a33a2c
Author: changwan <changwan@chromium.org>
Date: Mon Mar 28 23:48:09 2016

Clarify ShowKeyboardResultReceiver comment in ContentViewCore

Clarify the comment added at https://codereview.chromium.org/1809013002/
which is somewhat misleading since objects are not permanently leaked.

BUG= 595613 

Review URL: https://codereview.chromium.org/1838773002

Cr-Commit-Position: refs/heads/master@{#383612}

[modify] https://crrev.com/fccdae63cab073c8076d42edf15c4a8424a33a2c/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Sign in to add a comment