Release some resources on unload

This commit is contained in:
Raymond Lee 2010-08-12 12:36:58 +08:00
parent 606e0b8349
commit a77313ad4e
4 changed files with 51 additions and 12 deletions

View File

@ -570,7 +570,7 @@ window.GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
$el = iQ(a);
item = Items.item($el);
}
Utils.assertThrow(!item.parent || item.parent == this,
Utils.assertThrow(!item.parent || item.parent == this,
"shouldn't already be in another groupItem");
item.removeTrenches();
@ -1353,6 +1353,12 @@ window.GroupItems = {
init: function() {
},
// ----------
// Function: uninit
uninit : function() {
this.groupItems = null;
},
// ----------
// Function: getNextID
// Returns the next unused groupItem ID.
@ -1486,7 +1492,6 @@ window.GroupItems = {
if (groupItem == this._activeGroupItem)
this._activeGroupItem = null;
},
// ----------

View File

@ -57,6 +57,12 @@ let Storage = {
getService(Ci.nsISessionStore);
},
// ----------
// Function: uninit
uninit : function() {
this._sessionStore = null;
},
// ----------
// Function: wipe
// Cleans out all the stored data, leaving empty objects.

View File

@ -670,6 +670,7 @@ window.TabItems = {
_heartbeatOn: false,
_heartbeatTiming: 100, // milliseconds between beats
_lastUpdateTime: Date.now(),
_eventListeners: [],
// ----------
// Function: init
@ -679,35 +680,36 @@ window.TabItems = {
var self = this;
// When a tab is opened, create the TabItem
AllTabs.register("open", function(tab) {
this._eventListeners["open"] = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
setTimeout(function() { // Marshal event from chrome thread to DOM thread
self.link(tab);
}, 1);
});
}
// When a tab's content is loaded, show the canvas and hide the cached data
// if necessary.
AllTabs.register("attrModified", function(tab) {
this._eventListeners["attrModified"] = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
setTimeout(function() { // Marshal event from chrome thread to DOM thread
self.update(tab);
}, 1);
});
}
// When a tab is closed, unlink.
AllTabs.register("close", function(tab) {
this._eventListeners["close"] = function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
setTimeout(function() { // Marshal event from chrome thread to DOM thread
self.unlink(tab);
}, 1);
});
}
for (let name in this._eventListeners) {
AllTabs.register(name, this._eventListeners[name]);
}
// For each tab, create the link.
AllTabs.tabs.forEach(function(tab) {
@ -719,6 +721,18 @@ window.TabItems = {
});
},
// ----------
// Function: uninit
uninit: function() {
for (let name in this._eventListeners) {
AllTabs.unregister(name, this._eventListeners[name]);
}
this.items = null;
this._eventListeners = null;
this._lastUpdateTime = null;
this._tabsWaitingForUpdate = null;
},
// ----------
// Function: update
// Takes in a xul:tab.
@ -779,7 +793,7 @@ window.TabItems = {
if (!tabItem.reconnected && (oldURL == 'about:blank' || !oldURL))
this.reconnect(tabItem);
tabItem.save();
}

View File

@ -102,7 +102,7 @@ var UIManager = {
gWindow.addEventListener("tabviewshow", function() {
self.showTabView(true);
}, false);
// ___ currentTab
this._currentTab = gBrowser.selectedTab;
@ -127,6 +127,9 @@ var UIManager = {
tab.hidden = false;
});
});
iQ(window).bind("unload", function() {
self.uninit();
});
gWindow.addEventListener("tabviewhide", function() {
var activeTab = self.getActiveTab();
@ -226,6 +229,17 @@ var UIManager = {
}
},
uninit: function() {
TabItems.uninit();
GroupItems.uninit();
Storage.uninit();
this._currentTab = null;
this._pageBounds = null;
this._reorderTabItemsOnShow = null;
this._reorderTabsOnHide = null;
},
// ----------
// Function: getActiveTab
// Returns the currently active tab as a <TabItem>