Created
July 3, 2012 18:55
-
-
Save Ventero/3041936 to your computer and use it in GitHub Desktop.
Greasemonkey issue 1578
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
diff --git a/content/browser.js b/content/browser.js | |
index e6e9556..13d1c27 100644 | |
--- a/content/browser.js | |
+++ b/content/browser.js | |
@@ -335,6 +335,16 @@ function GM_showPopup(aEvent) { | |
GM_MenuCommander.onPopupShowing(menuCommandPopup); | |
} | |
+/** | |
+ * Clean up the menu after it hides to prevent memory leaks | |
+ */ | |
+function GM_hidePopup(aEvent) { | |
+ var popup = aEvent.target; | |
+ | |
+ var menuCommandPopup = popup.getElementsByTagName('menupopup')[0]; | |
+ if(menuCommandPopup) GM_MenuCommander.destroyItems(menuCommandPopup); | |
+} | |
+ | |
// Short-term workaround for #1406: Tab Mix Plus breaks opening links in | |
// new tabs because it depends on this function, and incorrectly checks for | |
diff --git a/content/browser.xul b/content/browser.xul | |
index 14cbb2f..d9af0eb 100644 | |
--- a/content/browser.xul | |
+++ b/content/browser.xul | |
@@ -52,6 +52,7 @@ | |
> | |
<menupopup | |
onpopupshowing="GM_showPopup(event);" | |
+ onpopuphiding="GM_hidePopup(event);" | |
onclick="GM_popupClicked(event);event.stopPropagation();" | |
oncommand="GM_popupClicked(event);event.stopPropagation();" | |
oncontextmenu="event.preventDefault();" | |
diff --git a/content/menucommander.js b/content/menucommander.js | |
index 4c61ad8..8d37004 100644 | |
--- a/content/menucommander.js | |
+++ b/content/menucommander.js | |
@@ -6,7 +6,8 @@ GM_MenuCommander.createMenuItem = function(command) { | |
var menuItem = document.createElement("menuitem"); | |
menuItem.setAttribute("label", command.name); | |
if ('function' == typeof command.commandFunc) { | |
- menuItem.addEventListener("command", command.commandFunc, true); | |
+ menuItem._callback = command.commandFunc; | |
+ menuItem.setAttribute("oncommand", "this._callback();"); | |
} | |
if (command.accessKey) { | |
@@ -16,6 +17,14 @@ GM_MenuCommander.createMenuItem = function(command) { | |
return menuItem; | |
}; | |
+GM_MenuCommander.destroyItems = function(aMenuPopup) { | |
+ var menuItems = aMenuPopup.getElementsByTagName("menuitem"); | |
+ for(var i = menuItems.length - 1; i >= 0; i--) { | |
+ delete menuItems[i]._callback; | |
+ } | |
+ GM_util.emptyEl(aMenuPopup); | |
+}; | |
+ | |
GM_MenuCommander.onPopupShowing = function(aMenuPopup) { | |
GM_util.emptyEl(aMenuPopup); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment