Created
October 21, 2013 22:02
-
-
Save jsantell/7091737 to your computer and use it in GitHub Desktop.
Window memory leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Opens/closes windows using either Jetpack wrappers (`USE_JETPACK`) or using the `windowWatcher`. | |
* Either way, does not reclaim memory in: | |
* explicit -> window-objects -> top(none)/detached/window([system]) | |
*/ | |
let { Cc, Ci } = require('chrome'); | |
let WW = Cc['@mozilla.org/embedcomp/window-watcher;1'].getService(Ci.nsIWindowWatcher); | |
let { open } = require('sdk/window/utils'); | |
let { setInterval, clearInterval } = require('sdk/timers'); | |
let URI = 'chrome://browser/content/browser.xul'; | |
let INTERVAL = 100; | |
let count = 0; | |
let MAX = 100; | |
let USE_JETPACK = 0; | |
let lastWindow; | |
let timer = setInterval(() => { | |
if (lastWindow) lastWindow.close(); | |
lastWindow = openWindow(); | |
console.log("Opening " + count); | |
if (++count > MAX) clearInterval(timer); | |
}, INTERVAL); | |
function openWindow () { | |
if (USE_JETPACK) | |
return open(URI, { | |
name : 'simple addon', | |
features: { | |
width : 100, | |
height : 100, | |
chrome : true, | |
left : 100, | |
top : 100 | |
} | |
}); | |
else | |
return WW.openWindow(null, URI, 'a simple addon', 'width=100,height=100,chrome,left=100,top=100', null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Open/closes windows using `windowWatcher` | |
* | |
* Reclaims memory in | |
* explicit -> window-objects -> top(none)/detached/window([system]) | |
*/ | |
let WW = Components.classes['@mozilla.org/embedcomp/window-watcher;1'].getService(Components.interfaces.nsIWindowWatcher); | |
let URI = 'chrome://browser/content/browser.xul'; | |
let INTERVAL = 100; | |
let count = 0; | |
let MAX = 100; | |
let lastWindow; | |
let timer = setInterval(() => { | |
close(); | |
console.log(count); | |
if (++count > MAX) clearInterval(timer); | |
open(); | |
}, INTERVAL); | |
function open () { | |
lastWindow = WW.openWindow(null, URI, 'a simple addon', 'width=100,height=100,chrome,left=100,top=100', null); | |
} | |
function close () { | |
if (lastWindow) lastWindow.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not seems to leak. So maybe it's
window/utils
??