Yet another leak has been identified on context-menu on addon disabling.
We are leaking all modules when a module is using `Item` class from context-menu.
var cm = require("context-menu");
label: "Go to Resolved Link"
I'm checking only on master, the leak may be different with older SDK version.
So web content never leaks here -- the issue is that, if the add-on uses a context-menu item, the add-on's modules will stick around even after the add-on is disabled?
(In reply to Justin Lebar [:jlebar] from comment #1)
> So web content never leaks here -- the issue is that, if the add-on uses a
> context-menu item, the add-on's modules will stick around even after the
> add-on is disabled?
Yes, that's exactly it.
A first improvement could be to avoid leaking all modules, but only context-menu related ones. See bug 764866.
Can we test on stabilization and see if it occurs there too?
Created attachment 638414 [details]
Pull request 475
This leak is due to some leak in content-proxy.js.
We are leaking JS proxies between the time we are destroying the content script and the time of the destruction of the content document.
When the related content document is destroyed, we free everything.
So that if you close all tabs opened when the addon was active (including about:addons!), we do not leak addons compartments.
In most cases, we destroy the content script when the related document is destroyed. But not in case of addon disabling ... So it is worth fixing this.
The fix itself is quite easy. Instead of storing the JS proxy on the xraywrapper itself, we use a WeakMap.
Commits pushed to master at https://github.com/mozilla/addon-sdk
Bug 764831: Avoid leaking JS proxies on addon disabling.
Merge pull request #475 from ochameau/bug/764831-avoid-leaking-js-proxies
Bug 764831: Avoid leaking JS proxies on addon disabling. r=@gozala
It would be cool to get this fix pushed into stabilization. It isn't a severe leak as related objects are freed whent the tab is closed, but it may help investigate on more important leaks if we aren't hitting this one at first place.
Reverted per bug 781619 comment 11:
Cherry-picked to stabilization:
It appears to be a bit more harmfull than what I was thinking.
In case of page-mod, when we apply a content script on an iframe and access to `window.parent`, we end up leaking iframe's content script until the parent document is destroyed.
So that, in bug 780391, wallflower addon is leaking all ecmascript test iframes until we close ecmascript tab.
That's because we cache JS proxies on the xraywrapper itself. The proxy and its sandbox are kept alive until the related xray is destroyed. In case of window.parent and any cross compartment usages, it ends up being quite bad behavior!
With Weakmap patch, wallflower isn't leaking. But Weakmap doesn't work on all kind of wrappers, so that the cache may loose some proxies. But from what I know it is the only way to avoid leaking here.
I tried to use Components.utils.getWeakReference without much success, it still leaks when trying to access window.parent while running ecmascript tests.
I'm not able to come up with any ideal fix. We either leak or miss some proxies instances from cache. Missing proxies from cache means that for the same webpage object, we will generate two distinct objects which will have different set of expendos.
From what I can see, here is the kind of object that can't be used in weakmaps: Storage, Events, Location, XPath objects, ImageData, ...
As Andrew said in bug 761620 comment 0, it works only for node wrappers.
When bug 761620 will land, we will be able to detect cases where weakmap fails to use the key and switch back to safe-leaky way of doing. But in the meantime I don't know exactly how to address this.
*** Bug 779224 has been marked as a duplicate of this bug. ***
Actually this bug can be considered as fixed, thanks to bug 786976, and the removal of JS proxies.
And even if the original report mentioned context-menu, this leak was'nt related to context-menu, but worker code and all dependent APIs.