android.os.StrictMode$InstanceCountViolation: class org.mozilla.gecko.BrowserApp

RESOLVED FIXED in Firefox 51

Status

()

Firefox for Android
General
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: jchen, Assigned: jchen)

Tracking

unspecified
Firefox 51
All
Android
Points:
---

Firefox Tracking Flags

(firefox51 fixed)

Details

Attachments

(4 attachments)

(Assignee)

Description

2 years ago
When we recreate BrowserApp instances, previous instances are leaked as shown by InstanceCountViolation in the logcat, e.g.,

> android.os.StrictMode$InstanceCountViolation: class org.mozilla.gecko.BrowserApp; instances=nnn; limit=1

I looked through a memory profile and there were several sources of leaks.
(Assignee)

Comment 1

2 years ago
Created attachment 8785366 [details] [diff] [review]
a. Fix BrowserApp leak in GeckoAccessibility (v1)

Move registration of AccessibilityManager listeners to GeckoApplication,
and change all Context references to the application context, so that
GeckoAccessibility doesn't leak old BrowserApp instances as new
BrowserApp instances are created.
Attachment #8785366 - Flags: review?(s.kaspari)
(Assignee)

Comment 2

2 years ago
Created attachment 8785367 [details] [diff] [review]
b. Fix BrowserApp leaks in event registration (v1)

Unregister certain events in BrowserApp and GeckoApp to prevent
BrowserApp from leaking. Also, properly unregister event listeners in
PageActionLayout to prevent BrowserApp leaks, because
PageActionLayout.onDestroy never got called before.
Attachment #8785367 - Flags: review?(s.kaspari)
(Assignee)

Comment 3

2 years ago
Created attachment 8785369 [details] [diff] [review]
c. Properly remove pref handler in NativePanZoomController (v1)

Properly remove pref handler on destroy to prevent leaking BrowserApp.
Attachment #8785369 - Flags: review?(rbarker)
(Assignee)

Comment 4

2 years ago
Created attachment 8785370 [details] [diff] [review]
d. Use application context to prevent BrowserApp leaks (v1)

Use application context for delayed callbacks to prevent leaking the
BrowserApp instance. Also, use application context for accessing
Distribution, to prevent leaking old BrowserApp instances, and to avoid
using a destroyed Context. Finally, attach AudioFocusAgent to the
application context instead of the BrowserApp context to avoid leaking
BrowserApp.
Attachment #8785370 - Flags: review?(s.kaspari)
Attachment #8785369 - Flags: review?(rbarker) → review+
Attachment #8785366 - Flags: review?(s.kaspari) → review+
Attachment #8785367 - Flags: review?(s.kaspari) → review+
Attachment #8785370 - Flags: review?(s.kaspari) → review+
Awesome!

Comment 6

2 years ago
Pushed by nchen@mozilla.com:
https://hg.mozilla.org/integration/fx-team/rev/18a92c5e14e6
a. Fix BrowserApp leak in GeckoAccessibility; r=sebastian
https://hg.mozilla.org/integration/fx-team/rev/2c6691bd8a71
b. Fix BrowserApp leaks in event registration; r=sebastian
https://hg.mozilla.org/integration/fx-team/rev/322bce6bc1d6
c. Properly remove pref handler in NativePanZoomController; r=rbarker
https://hg.mozilla.org/integration/fx-team/rev/803dba6b6691
d. Use application context to prevent BrowserApp leaks; r=sebastian

Comment 7

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/18a92c5e14e6
https://hg.mozilla.org/mozilla-central/rev/2c6691bd8a71
https://hg.mozilla.org/mozilla-central/rev/322bce6bc1d6
https://hg.mozilla.org/mozilla-central/rev/803dba6b6691
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox51: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 51
You need to log in before you can comment on or make changes to this bug.