Fix leaks by avoiding closure and unregistering listener. b=231266 r=bryner sr=brendan

This commit is contained in:
dbaron%dbaron.org 2004-01-17 22:41:38 +00:00
Родитель 197d8abe67
Коммит d7a8d3b552
2 изменённых файлов: 31 добавлений и 35 удалений

Просмотреть файл

@ -196,23 +196,17 @@ function UpdatePageReport(event)
}
#ifdef MOZ_ENABLE_XREMOTE
function RegisterTabOpenObserver()
{
const observer = {
observe: function(subject, topic, data)
{
if (topic != "open-new-tab-request" || subject != window)
return;
const gTabOpenObserver = {
observe: function(subject, topic, data)
{
if (topic != "open-new-tab-request" || subject != window)
return;
delayedOpenTab(data);
}
};
const service = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
service.addObserver(observer, "open-new-tab-request", false);
}
delayedOpenTab(data);
}
};
#endif
function Startup()
{
gBrowser = document.getElementById("content");
@ -246,7 +240,9 @@ function Startup()
.getService(Components.interfaces.nsIXRemoteService);
remoteService.addBrowserInstance(window);
RegisterTabOpenObserver();
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(gTabOpenObserver, "open-new-tab-request", false);
#endif
#endif
@ -483,6 +479,10 @@ function Shutdown()
remoteService = Components.classes["@mozilla.org/browser/xremoteservice;1"]
.getService(Components.interfaces.nsIXRemoteService);
remoteService.removeBrowserInstance(window);
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(gTabOpenObserver, "open-new-tab-request");
#endif
try {
gBrowser.removeProgressListener(window.XULBrowserWindow);

Просмотреть файл

@ -411,25 +411,15 @@ function allLeftButtonsAreHidden()
return true;
}
function RegisterTabOpenObserver()
{
const observer = {
observe: function(subject, topic, data)
{
if (topic != "open-new-tab-request" || subject != window)
return;
const gTabOpenObserver = {
observe: function(subject, topic, data)
{
if (topic != "open-new-tab-request" || subject != window)
return;
delayedOpenTab(data);
}
};
var service = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
service.addObserver(observer, "open-new-tab-request", false);
// Null out service variable so the closure of the observer doesn't
// own the service and create a cycle (bug 170022).
service = null;
}
delayedOpenTab(data);
}
};
function Startup()
{
@ -634,7 +624,9 @@ function Startup()
.getService(Components.interfaces.nsIXRemoteService);
remoteService.addBrowserInstance(window);
RegisterTabOpenObserver();
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(gTabOpenObserver, "open-new-tab-request", false);
}
}
@ -713,6 +705,10 @@ function Shutdown()
remoteService = Components.classes[XREMOTESERVICE_CONTRACTID]
.getService(Components.interfaces.nsIXRemoteService);
remoteService.removeBrowserInstance(window);
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(gTabOpenObserver, "open-new-tab-request", false);
}
try {