I just landed a patch for bug 1409115 that fixes a leak where a global data
structure (some per-process service worker queue) holds alive a DOM
promise, which ends up leaking the window forever. Fundamentally, holding
alive a DOM promise, which holds alive its window, from a data structure
that is not in turn held alive by the window is prone to leaking the
window, which leads to bad performance issues (both memory usage and speed).

To make this easier to avoid, I added a new class, PromiseWindowProxy, that
lets you use a promise in this way without having to worry about leaking.
It is a kind of weak reference, but it is strong enough to keep the promise
alive as long as the window and proxy are both alive.

If you know of any other places that might be using this problematic
pattern, please file bugs.

Here's my comment in the code that goes into a little more detail:

// When a data structure is waiting to resolve a promise from a//
window, but that data structure is not owned by that window, there//
exists a dilemma://// 1) If the promise is never resolved, and the
non-window data// structure is keeping alive the promise, the
promise's window will// be leaked.//// 2) Something has to keep the
promise alive from native code in case// script has dropped all direct
references to it, but the promise is// later resolved.////
PromiseWindowProxy solves this dilemma for the non-window data//
structure. It solves (1) by only keeping a weak reference to the//
promise. It solves (2) by adding a strong reference to the promise//
on the window itself. This ensures that as long as both the//
PromiseWindowProxy and the window are still alive that the promise//
will remain alive. This strong reference is cycle collected, so it//
won't cause the window to leak.

Andrew
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to