更新
以下更改MochaUI closingJobs功能是大改善了我以前在這裏公佈。主要變化是現在iframe的onunload事件是通過更改src屬性手動調用的,而不是在windowEl.destroy方法從DOM中移除iframe時被觸發。 (從here得到了這個想法)。
如果您想使用此代碼,只需刪除現有的closingJobs函數並複製粘貼此代碼的位置。它應該兼容0.9.7和0.9.8 MochaUI,以及Mootools 1.2.4或1.3。
closingJobs: function(windowEl){
windowEl.setStyle('visibility', 'hidden');
var instances = MUI.Windows.instances;
var instance_id = windowEl.id
var cleanup_delay = 50;
/*
Reset canvases with width/height = 0.
This pretty reliably frees a few hundred Kb of
memory in chrome.
*/
instances[instance_id].canvasControlsEl.width = 0;
instances[instance_id].canvasControlsEl.height = 0;
instances[instance_id].canvasEl.width = 0;
instances[instance_id].canvasEl.height = 0;
if(instances[instance_id].options.loadMethod == 'iframe')
{
/*
The following line determines how long to delay the execution of
the windowEl.destroy function. The line below gives 10 milliseconds
per DOM element in the iframe's document.
You could probably do just as well with a hard-coded value.
*/
cleanup_delay = instances[instance_id].iframeEl.contentDocument.getElementsByTagName("*").length * 10;
/*
Set the Browser property in the iframe's window to Internet Explorer.
This causes Mootools to run its purge function, which iterates over
all the iframe document's DOM elements, removing events/attributes etc.
Assuming you have mootools included in the iframe content.
*/
if(instances[instance_id].iframeEl.contentDocument.defaultView.MooTools)
{
if(instances[instance_id].iframeEl.contentDocument.defaultView.MooTools.version.contains("1.3"))
instances[instance_id].iframeEl.contentDocument.defaultView.Browser.ie = true;
else
instances[instance_id].iframeEl.contentDocument.defaultView.Browser.Engine.trident = true;
}
instances[instance_id].iframeEl.src = "javascript:false";
}
MUI.cleanWindow.delay(cleanup_delay, null, windowEl);
},
cleanWindow: function(windowEl)
{
var instances = MUI.Windows.instances;
var instance_id = windowEl.id
if (Browser.ie){
windowEl.dispose();
}
else {
windowEl.destroy();
}
instances[instance_id].fireEvent('onCloseComplete');
/*
Changed - Only execute getWindowWithHighestZindex() and focusWindow()
functions if there will actually be open windows after the
current one closes.
*/
if (instances[instance_id].options.type != 'notification' && instances.__count__ > 1){
var newFocus = MUI.getWindowWithHighestZindex();
MUI.focusWindow(newFocus);
}
if (this.loadingWorkspace) this.windowUnload();
if (MUI.Dock && $(MUI.options.dock) && instances[instance_id].options.type == 'window'){
var currentButton = $(instances[instance_id].options.id + '_dockTab');
if (currentButton != null){
MUI.Dock.dockSortables.removeItems(currentButton).destroy();
currentButton = null; //Is this necessary?
}
MUI.Desktop.setDesktopSize();
}
//Changed - moved this to the end of the function.
delete instances[instance_id];
}
非常有趣的問題,並很好的解釋。我不確定究竟是什麼罪魁禍首,雖然我會警告你有可能不會有解決辦法。或者如果有一個,不是一個容易的。 Google對編程採取了非常懶惰的方式。雖然Chrome似乎加載速度最快,並且使用的是每個主要瀏覽器的最小內存,但它充斥着我在Firefox或Opera中不會想到的錯誤。與Android和iOS相同。 – stevendesu 2010-10-31 17:16:06
我在Google的Chrome網站管理員幫助論壇上發佈了一個非常詳細/冗長的此問題版本,但沒有得到答覆,所以這次我決定讓它更具針對性!我同意這看起來像一個錯誤(或者Chrome如何確定哪些對象被垃圾收集)。就好像Chrome最小化時發生的垃圾收集更加劇烈,我的窗口對象也許並不完全是Chrome的標準。感謝您的評論! – freenatec 2010-10-31 17:35:06
@steven_desu:Google不僅對編程採取懶惰的方式,而且對於用戶提出的任何投訴或問題似乎都表現出冷漠的態度。 – 2010-10-31 19:27:21