Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Issue 1809013002: Fix webview memory leak when keyboard was shown (Closed)

Created:
4 years, 9 months ago by Changwan Ryu
Modified:
4 years, 9 months ago
CC:
chromium-reviews, darin-cc_chromium.org, jam, android-webview-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

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 Committed: https://crrev.com/fcc3fbf1652285b2a89eabd092d35d0fdf199ac2 Cr-Commit-Position: refs/heads/master@{#381891}

Patch Set 1 #

Patch Set 2 : #

Patch Set 3 : changed to weakreference approach #

Patch Set 4 : fixed nits #

Patch Set 5 : keep a single instance instead of leaking many #

Total comments: 4

Patch Set 6 : added comments and fixed nits #

Patch Set 7 : removed thread.sleep from test #

Total comments: 2

Patch Set 8 : do not call showImeIfNeeded #

Total comments: 6

Patch Set 9 : address boliu@'s comments #

Patch Set 10 : #

Total comments: 2

Patch Set 11 : removed final #

Patch Set 12 : fixed nits #

Unified diffs Side-by-side diffs Delta from patch set Stats (+98 lines, -23 lines) Patch
M android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java View 1 2 3 4 5 6 7 8 9 10 3 chunks +40 lines, -3 lines 0 comments Download
M content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java View 1 2 3 4 5 6 7 8 9 10 11 4 chunks +58 lines, -20 lines 0 comments Download

Messages

Total messages: 37 (10 generated)
Changwan Ryu
4 years, 9 months ago (2016-03-17 09:00:07 UTC) #3
boliu
Did you actually test that ResultReceiver is the *only* reference that framework code holds, ie ...
4 years, 9 months ago (2016-03-17 16:41:21 UTC) #5
boliu
Android has said that WeakReference is the right thing to do here. And I verified ...
4 years, 9 months ago (2016-03-17 22:17:03 UTC) #6
Changwan Ryu
PTAL https://codereview.chromium.org/1809013002/diff/80001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://codereview.chromium.org/1809013002/diff/80001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode122 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:122: containerView.getAwContents().getWebContents().showImeIfNeeded(); On 2016/03/17 16:41:20, boliu wrote: > wrong ...
4 years, 9 months ago (2016-03-18 00:26:58 UTC) #7
Ted C
CVC - lgtm
4 years, 9 months ago (2016-03-18 00:35:19 UTC) #9
boliu
On 2016/03/18 00:35:19, Ted C wrote: > CVC - lgtm
4 years, 9 months ago (2016-03-18 00:40:27 UTC) #10
boliu
On 2016/03/18 00:40:27, boliu wrote: > On 2016/03/18 00:35:19, Ted C wrote: > > CVC ...
4 years, 9 months ago (2016-03-18 00:45:53 UTC) #11
boliu
On 2016/03/18 00:45:53, boliu wrote: > On 2016/03/18 00:40:27, boliu wrote: > > On 2016/03/18 ...
4 years, 9 months ago (2016-03-18 01:02:12 UTC) #12
Changwan Ryu
On 2016/03/18 01:02:12, boliu wrote: > On 2016/03/18 00:45:53, boliu wrote: > > On 2016/03/18 ...
4 years, 9 months ago (2016-03-18 01:30:34 UTC) #14
boliu
https://chromiumcodereview.appspot.com/1809013002/diff/120001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://chromiumcodereview.appspot.com/1809013002/diff/120001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode138 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:138: CriteriaHelper.pollForUIThreadCriteria(new Criteria() { Need to do this for both ...
4 years, 9 months ago (2016-03-18 01:37:14 UTC) #15
Changwan Ryu
https://chromiumcodereview.appspot.com/1809013002/diff/120001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://chromiumcodereview.appspot.com/1809013002/diff/120001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode138 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:138: CriteriaHelper.pollForUIThreadCriteria(new Criteria() { On 2016/03/18 01:37:14, boliu wrote: > ...
4 years, 9 months ago (2016-03-18 01:54:21 UTC) #16
boliu
https://chromiumcodereview.appspot.com/1809013002/diff/140001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://chromiumcodereview.appspot.com/1809013002/diff/140001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode110 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:110: public void testShowSoftKeyboardAndGcOnce() throws Throwable { can you rename ...
4 years, 9 months ago (2016-03-18 01:58:52 UTC) #17
Changwan Ryu
https://chromiumcodereview.appspot.com/1809013002/diff/140001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://chromiumcodereview.appspot.com/1809013002/diff/140001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode110 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:110: public void testShowSoftKeyboardAndGcOnce() throws Throwable { On 2016/03/18 01:58:52, ...
4 years, 9 months ago (2016-03-18 02:15:28 UTC) #18
boliu
lgtm https://chromiumcodereview.appspot.com/1809013002/diff/180001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://chromiumcodereview.appspot.com/1809013002/diff/180001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode115 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:115: final ResultReceiver resultReceivers[] = new ResultReceiver[MAX_IDLE_INSTANCES + 1]; ...
4 years, 9 months ago (2016-03-18 02:17:11 UTC) #19
Changwan Ryu
https://chromiumcodereview.appspot.com/1809013002/diff/180001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java File android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java (right): https://chromiumcodereview.appspot.com/1809013002/diff/180001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java#newcode115 android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java:115: final ResultReceiver resultReceivers[] = new ResultReceiver[MAX_IDLE_INSTANCES + 1]; On ...
4 years, 9 months ago (2016-03-18 02:19:55 UTC) #20
Changwan Ryu
tedchoc@, I added getNewShowKeyboardReceiver() method for testing after your lgtm. I'd like to submit this ...
4 years, 9 months ago (2016-03-18 02:28:14 UTC) #21
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1809013002/190003 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1809013002/190003
4 years, 9 months ago (2016-03-18 02:28:51 UTC) #24
commit-bot: I haz the power
Committed patchset #12 (id:190003)
4 years, 9 months ago (2016-03-18 04:55:56 UTC) #26
commit-bot: I haz the power
Patchset 12 (id:??) landed as https://crrev.com/fcc3fbf1652285b2a89eabd092d35d0fdf199ac2 Cr-Commit-Position: refs/heads/master@{#381891}
4 years, 9 months ago (2016-03-18 04:58:06 UTC) #28
yukawa
Hey, I feel that the CL description > (snip) ResultReceiver will still be leaked, > ...
4 years, 9 months ago (2016-03-18 05:07:44 UTC) #29
Changwan Ryu
On 2016/03/18 05:07:44, yukawa wrote: > Hey, > > I feel that the CL description ...
4 years, 9 months ago (2016-03-18 05:15:36 UTC) #30
Ted C
On 2016/03/18 05:15:36, Changwan Ryu wrote: > On 2016/03/18 05:07:44, yukawa wrote: > > Hey, ...
4 years, 9 months ago (2016-03-18 16:59:46 UTC) #31
hush (inactive)
Hello, (i'm the sheriff) this CL causes our internal bot failure: ******************************************************************************** FindBugs run via: ...
4 years, 9 months ago (2016-03-18 17:23:36 UTC) #33
hush (inactive)
After reading the comments, it seems we need to add @SuppressFBWarnings("UC_USELESS_OBJECT")
4 years, 9 months ago (2016-03-18 17:26:27 UTC) #34
boliu
Findbugs is complaining that that it's only assigned to once, but never used maybe? I ...
4 years, 9 months ago (2016-03-18 17:27:25 UTC) #35
boliu
On 2016/03/18 17:26:27, hush wrote: > After reading the comments, it seems we need to ...
4 years, 9 months ago (2016-03-18 17:27:53 UTC) #36
hush (inactive)
4 years, 9 months ago (2016-03-18 17:30:08 UTC) #37
Message was sent while issue was closed.
On 2016/03/18 17:26:27, hush wrote:
> After reading the comments, it seems we need to add    
> @SuppressFBWarnings("UC_USELESS_OBJECT")

this fixes findbugs https://codereview.chromium.org/1815143003/

Powered by Google App Engine
This is Rietveld 408576698