Closed Bug 899354 Opened 11 years ago Closed 11 years ago

BrowserElementParent isn't unregistering visibilityChangeHandler event listeners

Categories

(Firefox OS Graveyard :: Gaia, defect, P1)

ARM
Gonk (Firefox OS)
defect

Tracking

(blocking-b2g:leo+, firefox23 wontfix, firefox24 wontfix, firefox25 fixed, b2g18 fixed, b2g18-v1.0.0 wontfix, b2g18-v1.0.1 wontfix, b2g-v1.1hd fixed)

RESOLVED FIXED
1.1 QE5
blocking-b2g leo+
Tracking Status
firefox23 --- wontfix
firefox24 --- wontfix
firefox25 --- fixed
b2g18 --- fixed
b2g18-v1.0.0 --- wontfix
b2g18-v1.0.1 --- wontfix
b2g-v1.1hd --- fixed

People

(Reporter: mccr8, Assigned: justin.lebar+bug)

References

Details

(Keywords: perf, Whiteboard: [MemShrink] [c=memory u=1.1] QARegressExclude)

Attachments

(1 file)

See bug 898990 for STR. After around 3 days of running there are around 7400 event listeners that appears to be from BEP registered on a single nsGlobalWindow. These are visibilityChangeHandler, ignoreClearCacheOn and ignoreClearCacheOff. The latter two do not appear in any Mozilla repo, so it isn't clear where they are from, but they look like they are some other BEP event listener. There are the same number of each of the three. visibilityChangeHandler comes from here: http://mxr.mozilla.org/mozilla-central/source/dom/browser-element/BrowserElementParent.jsm#70
The visibilityChangeHandler is meant to hang around for as long as the BEP hangs around. So what we do is, when we get a visibilitychange notification, we check whether the BEP is still alive (using a weak ref). If it's not alive, we unregister the listener. It's not clear to me how to do better than this, without some sort of notification when an object goes away, or without an iterable weakset.
Whiteboard: [MemShrink]
Andrew suggested that, as a hack, we could keep a list of weakrefs and iterate over it every time we add to it. That might be sufficient, and a sufficiently small change to be OK for b2g18.
I think it is okay to use Cu.nondeterministicWeakMapKeys. It was intended to just be a testing function, but using that seems less hacky than some kind of set of XPCOM weak references that we have to manually purge. It is worrying that we can't implement this pattern in "real" JS.
I'm not going to try to fix the ignoreClearCache{On,Off} business, since that's a partner customization which we don't even have the complete source code for. It's not even clear to me whether we should be looking at that source code, given that it's not being provided in compliance with the MPL.
Summary: BrowserElementParent isn't unregistering visibilityChangeHandler event listeners (plus two others?) → BrowserElementParent isn't unregistering visibilityChangeHandler event listeners
Assignee: nobody → justin.lebar+bug
This prevents a leak when we run tests that create thousands of BrowserElementParents without ever turning the screen off.
Attachment #783343 - Flags: review?(khuey)
Depends on: 899759
Comment on attachment 783343 [details] [diff] [review] Patch, v1: Only ever add one visibilitychange listener to BrowserElementParent's owner window. Review of attachment 783343 [details] [diff] [review]: ----------------------------------------------------------------- Fun.
Attachment #783343 - Flags: review?(khuey) → review+
When you uplift this, you'll need to change 'visibilitychange' to 'mozvisibilitychange' in two places. Merge conflicts should point this out, and this should be the only non-trivial merge conflict.
Blocks a blocker.
blocking-b2g: --- → leo+
On a side note, jlebar and I noticed that nsObserverService actually has a similar problem: weakly registered observers won't be cleared unless a notification happens. nsObserverService has the advantage that every observer gets notified for all topics, compared to event listeners, where only things for a particular event get triggered.
Status: NEW → ASSIGNED
Keywords: perf
Whiteboard: [MemShrink] → [MemShrink] [c=memory u=1.1]
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Needs a branch-specific patch for uplift.
Flags: needinfo?(justin.lebar+bug)
Target Milestone: --- → 1.1 QE5
> Needs a branch-specific patch for uplift. I think it was just what was described in comment 8. https://hg.mozilla.org/releases/mozilla-b2g18/rev/11bb1b0eefff
Flags: needinfo?(justin.lebar+bug)
Whiteboard: [MemShrink] [c=memory u=1.1] → [MemShrink] [c=memory u=1.1] QARegressExclude
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: