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

Issue 710612 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit 15 days ago
Closed: May 2018
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 1
Type: Bug

Blocked on:
issue 711056



Sign in to add a comment

Closing CCT leaks activity

Project Member Reported by dskiba@chromium.org, Apr 11 2017

Issue description

Repeatedly opening / closing (using back) CCTs increases number of views / contexts / activities in the browser process (as reported by dumpsys meminfo):

 Objects
               Views:      174         ViewRootImpl:        1
         AppContexts:        6           Activities:        2

 Objects
               Views:      223         ViewRootImpl:        1
         AppContexts:        8           Activities:        3

 Objects
               Views:      272         ViewRootImpl:        1
         AppContexts:       10           Activities:        4

 Objects
               Views:      321         ViewRootImpl:        1
         AppContexts:       12           Activities:        5

HPROF dump is attached. It has 5 activities: 4 CustomTabActivities and 1 ChromeTabbedActivity.

3 CustomTabActivities are kept alive by mConnectionTypeObservers:

→ root org.chromium.net.NetworkChangeNotifier@12d56ea0.mConnectionTypeObservers
→ org.chromium.base.ObserverList@13270630.mObservers
→ java.util.ArrayList@132706a8.elementData
→ java.lang.Object[10]@132706c0[1]
→ org.chromium.chrome.browser.contextualsearch.ContextualSearchTabHelper@132706f8.mTab
→ org.chromium.chrome.browser.tab.Tab@132a3f28.mWindowAndroid
→ org.chromium.chrome.browser.ChromeWindow@132a4178.mKeyboardAccessoryView
→ android.widget.HorizontalScrollView@132a44e8.mContext
→ org.chromium.chrome.browser.customtabs.CustomTabActivity@132a4ae0

One is alive by a different reason:

→ root class org.chromium.chrome.browser.offlinepages.OfflinePageTabObserver.sInstance
→ org.chromium.chrome.browser.offlinepages.OfflinePageTabObserver@1321bc70.mSnackbarManager
→ org.chromium.chrome.browser.snackbar.SnackbarManager@1321bd40.mActivity
→ org.chromium.chrome.browser.customtabs.CustomTabActivity@1321bd68
 
cct.hprof.gz
3.3 MB Download

Comment 1 by yus...@chromium.org, Apr 11 2017

Cc: -yus...@chromium.org
Labels: -Pri-3 M-58 Pri-1
Owner: yus...@chromium.org
Status: Started (was: Untriaged)
The first one is actually ChromeActivity leaking so applies to ChromeTabbedActivity as well.

Taking this one and adding labels to accelarate landing a fix to production.

Comment 2 by dskiba@chromium.org, Apr 11 2017

BTW, this is how "dumpsys meminfo" reports number of objects:

1. First it calls Runtime.getRuntime().gc() to clear unreachable objects
2. Then it calls VMDebug.countInstancesOfClasses() to get actual counts

See https://cs.corp.google.com/aosp-master/frameworks/base/core/java/android/app/ActivityThread.java?rcl=f954f2d5cc2d254b2e4c1c4df33caf3bd66843b0&l=1043

Maybe we can do the same in a test?
Project Member

Comment 3 by bugdroid1@chromium.org, Apr 12 2017

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

commit 810b810269e4329d50c089c26d77f47ea89b61ef
Author: yusufo <yusufo@chromium.org>
Date: Wed Apr 12 00:25:30 2017

Unregister from network changes on destroy in ContextualSearchTabHelper

This causes us to leak ChromeActivity instances and all the views
associated with them. In general we should always make sure to
unregister notifiers from application level singletons on destroy.

BUG= 710612 

Review-Url: https://codereview.chromium.org/2812143002
Cr-Commit-Position: refs/heads/master@{#463855}

[modify] https://crrev.com/810b810269e4329d50c089c26d77f47ea89b61ef/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java

Comment 4 by yus...@chromium.org, Apr 12 2017

Labels: Merge-Request-58
Project Member

Comment 5 by sheriffbot@chromium.org, Apr 12 2017

Labels: -Merge-Request-58 Merge-Review-58 Hotlist-Merge-Review
This bug requires manual review: We are only 12 days from stable.
Please contact the milestone owner if you have questions.
Owners: amineer@(Android), cmasso@(iOS), bhthompson@(ChromeOS), govind@(Desktop)

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Comment 6 by dskiba@chromium.org, Apr 12 2017

#3 fixed the leak, however the last closed CustomTabActivity still remains alive, referenced by:

→ root class org.chromium.chrome.browser.offlinepages.OfflinePageTabObserver.sInstance
→ org.chromium.chrome.browser.offlinepages.OfflinePageTabObserver@13109908.mContext
→ android.app.ContextImpl@13109928.mOuterContext
→ org.chromium.chrome.browser.customtabs.CustomTabActivity@13109a00

Comment 7 by yus...@chromium.org, Apr 12 2017

I think that one will keep moving from one activity to another. If you create another one, we wont have two activities. It leaves an extra activity even though we dont have any live.

That one was trickier to solve without changing the whole OfflineTabObserver idea which I feel like will have to go through the offline team.

This seemed like the quickest and most effective solution that can be cherrypicked
Labels: -Merge-Review-58 Merge-Approved-58
Merge approved for M58 branch 3029.
Project Member

Comment 9 by bugdroid1@chromium.org, Apr 12 2017

Labels: -merge-approved-58 merge-merged-3029
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/615aaeab8b12051181cff795d1a1e7683f9a38ba

commit 615aaeab8b12051181cff795d1a1e7683f9a38ba
Author: Yusuf Ozuysal <yusufo@google.com>
Date: Wed Apr 12 21:26:06 2017

Unregister from network changes on destroy in ContextualSearchTabHelper

This causes us to leak ChromeActivity instances and all the views
associated with them. In general we should always make sure to
unregister notifiers from application level singletons on destroy.

BUG= 710612 

Review-Url: https://codereview.chromium.org/2812143002
Cr-Commit-Position: refs/heads/master@{#463855}
Committed: https://chromium.googlesource.com/chromium/src/+/810b810269e4329d50c089c26d77f47ea89b61ef

patch from issue 2812143002 at patchset 1 (http://crrev.com/2812143002#ps1)

Review-Url: https://codereview.chromium.org/2812373002 .
Cr-Commit-Position: refs/branch-heads/3029@{#681}
Cr-Branched-From: 939b32ee5ba05c396eef3fd992822fcca9a2e262-refs/heads/master@{#454471}

[modify] https://crrev.com/615aaeab8b12051181cff795d1a1e7683f9a38ba/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java

Cc: yus...@chromium.org
Labels: -M-58 M-60
Owner: dskiba@chromium.org
Updating the milestone and sending back to dskiba@ for adding related tests. I will also fork the offline related issue as a separate bug.
Blockedon: 711056
Figuring out how to add this check to tests is a tough one, because most of our tests are not black-box, and so the tests themselves end up holding onto references to the activities. 

This would be a great check to add if we were to write some espresso tests though.

Related: LeakCanary ( bug 505909 ). Where LeakCanary kind of fell apart for me was the no way to make it work for instrumentation tests.
Project Member

Comment 14 by bugdroid1@chromium.org, May 9 2017

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

commit 3f4a47063c35627779a3e4d7464e1398bcbf6467
Author: olka <olka@chromium.org>
Date: Tue May 09 12:53:52 2017

Revert of Add tests to make sure closed CCT activities are not leaked. (patchset #7 id:120001 of https://codereview.chromium.org/2847263003/ )

Reason for revert:
org.chromium.chrome.browser.customtabs.CustomTabActivityTest#testClosedBackActivitiesNotLeaked flaky on chromium.linux/Android Tests

See  Issue 719909 

Original issue's description:
> Add tests to make sure closed CCT activities are not leaked.
>
> BUG=715724,  710612 
>
> Review-Url: https://codereview.chromium.org/2847263003
> Cr-Commit-Position: refs/heads/master@{#470057}
> Committed: https://chromium.googlesource.com/chromium/src/+/d50d8466d0bdae0b5ae8af4108ecaa1376ed5f21

TBR=tedchoc@chromium.org,yusufo@chromium.org,torne@chromium.org,dskiba@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=715724,  710612 

Review-Url: https://codereview.chromium.org/2866213003
Cr-Commit-Position: refs/heads/master@{#470295}

[modify] https://crrev.com/3f4a47063c35627779a3e4d7464e1398bcbf6467/base/android/java/src/org/chromium/base/ThreadUtils.java
[modify] https://crrev.com/3f4a47063c35627779a3e4d7464e1398bcbf6467/chrome/android/java/src/org/chromium/chrome/browser/toolbar/CustomTabToolbar.java
[modify] https://crrev.com/3f4a47063c35627779a3e4d7464e1398bcbf6467/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarManager.java
[modify] https://crrev.com/3f4a47063c35627779a3e4d7464e1398bcbf6467/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
[modify] https://crrev.com/3f4a47063c35627779a3e4d7464e1398bcbf6467/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTestBase.java
[modify] https://crrev.com/3f4a47063c35627779a3e4d7464e1398bcbf6467/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java

Status: Fixed (was: Started)

Sign in to add a comment