Open Bug 1678425 Opened 4 years ago Updated 2 years ago

Memory leak in GeckoEditable.mListener

Categories

(GeckoView :: Extensions, defect, P2)

Unspecified
All

Tracking

(Not tracked)

People

(Reporter: csadilek, Assigned: m_kato)

References

Details

(Whiteboard: [geckoview:m87] [geckoview:m94?] [geckoview:2022h2?])

Attachments

(3 files)

718.13 KB, application/x-zip-compressed
gabrielstrong
: feedback+
Details
7.79 MB, application/x-zip-compressed
Details
178.45 KB, image/png
Details

We've been fixing memory leaks in Fenix and there's one known leak left which looks to be a GV issue we'd need help with.

We are calling releaseSession when the view is detached but somehow end up in this state: The GC root being in native code, and the view being referenced via GeckoEditable.mListener. Since the GC root isn't in A-C/Fenix we'd need some help understanding what could go wrong here :).

STR in Fenix debug:

  • Open private tabs
  • Tap on notification to close all private tabs
  • Open a new private tab

LeakCanary:

┬───
│ GC Root: Global variable in native code
│
├─ org.mozilla.geckoview.GeckoEditable instance
│    Leaking: UNKNOWN
│    ↓ GeckoEditable.mListener
│                    ~~~~~~~~~
├─ org.mozilla.geckoview.GeckoInputConnection instance
│    Leaking: UNKNOWN
│    ↓ GeckoInputConnection.mTargetView
│                           ~~~~~~~~~~~
├─ mozilla.components.browser.engine.gecko.GeckoEngineView$geckoView$1 instance
│    Leaking: YES (View.mContext references a destroyed activity)
│    Anonymous subclass of mozilla.components.browser.engine.gecko.NestedGeckoView
│    mContext instance of org.mozilla.fenix.HomeActivity with mDestroyed = true
│    View#mParent is set
│    View#mAttachInfo is null (view detached)
│    View.mWindowAttachCount = 1
│    ↓ GeckoEngineView$geckoView$1.$context
├─ org.mozilla.fenix.HomeActivity instance
│    Leaking: YES (GeckoEngineView$geckoView$1↑ is leaking and Activity#mDestroyed is true)
│    ↓ HomeActivity.mFragments
├─ androidx.fragment.app.FragmentController instance
│    Leaking: YES (HomeActivity↑ is leaking)
│    ↓ FragmentController.mHost
├─ androidx.fragment.app.FragmentActivity$HostCallbacks instance
│    Leaking: YES (HomeActivity↑ is leaking)
│    ↓ FragmentActivity$HostCallbacks.mFragmentManager
├─ androidx.fragment.app.FragmentManagerImpl instance
│    Leaking: YES (HomeActivity↑ is leaking)
│    ↓ FragmentManagerImpl.mNonConfig
╰→ androidx.fragment.app.FragmentManagerViewModel instance
     Leaking: YES (ObjectWatcher was watching this because androidx.fragment.app.FragmentManagerViewModel received ViewModel#onCleared() callback)
     key = 14c16c55-9abe-433d-8578-ea1b78fc6a86
     watchDurationMillis = 59471
     retainedDurationMillis = 54469
Severity: -- → S3
Priority: -- → P2
Whiteboard: [geckoview:m86]
Flags: needinfo?(agi)
Flags: needinfo?(agi)
Priority: P2 → P1
Whiteboard: [geckoview:m86] → [geckoview:m87]
Rank: 3
Assignee: nobody → aklotz

Is this still a problem for you, Christian? I cannot reproduce this on an up-to-date local Fenix x AC x GV build.

Flags: needinfo?(csadilek)

I can't reproduce this anymore on the latest builds. Any idea what could cause this though? Definitely unclear how this went away :). If not, I guess we can close and re-open if we see it again?

Flags: needinfo?(csadilek)

There were some bug fixes in the GeckoEditable area recently. My best guess is that we fixed it there.

Yeah, let's just reopen if necessary.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → WORKSFORME
Status: RESOLVED → REOPENED
Resolution: WORKSFORME → ---

Gabe, could you provide the example app that you used to reproduce this in Bug 1719937?

Flags: needinfo?(gabrielstrong)
Rank: 3
Priority: P1 → P2
Whiteboard: [geckoview:m87] → [geckoview:m87][geckoview:m93?]

I'll try to make something I can distribute. Be aware that the Reference Browser (https://github.com/mozilla-mobile/reference-browser) has the same behavior/leak of the GeckoEditableChild although it also leaks the GeckoSession objects making it a poor diagnostic tool.

Flags: needinfo?(gabrielstrong)

This is a sample app demonstrating the issue with memory leaking from GeckoSession objects.
This sample was tested with the latest stable GeckoView version (90.0.20210716144314) on an emulator running Android 7.1.

This sample opens and closes GeckoSession instances up to the amount specified in MAX_SESSIONS in a sequential manner.

1st test:
Set MAX_SESSIONS to 10. Allow all 10 to open/close (screen will be black). Use Android Studio Profiler to force multiple GCs (allocated counts will decrease).
Perform a heap dump and verify that no instances of the sample's BrowserView class remain (this proves that the sample is not leaking its own view).
Verify that 10 instances of GeckoSession remain (along with many other Gecko objects attached to GeckoSession).
This shows that Android is unable to GC the GeckoSession instances.

2nd test:
Set MAX_SESSIONS to 0. Allow GeckoSession instances to be opened/closed for 1 hour (or more). Use Android Studio Profiler during this time to track memory usage and allocations.
Verify that there is a constant increase in memory usage and allocation counts.
Eventually the app will crash due to lack of memory.

Attachment #9232068 - Flags: feedback+

Heap dump after running the sample for 1 hour.

Attached image Profiler_Memory.PNG

Android Studio Profiler screenshot of memory usage after 1 hour.

De-assigning myself. Since we have a repro, I'm resetting priority.

Assignee: bugzilla → nobody
Status: REOPENED → NEW
Priority: P2 → --
Priority: -- → P2
Whiteboard: [geckoview:m87][geckoview:m93?] → [geckoview:m87][geckoview:m94?]

still relevant

Whiteboard: [geckoview:m87][geckoview:m94?] → [geckoview:m87] [geckoview:m94?] [geckoview:2022h2?]

Assigning this bug to Makoto. He will decide whether we need to prioritize it for 2022 H2.

Assignee: nobody → m_kato
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: