我注意到,使用firefox幾個小時後,它得到更多的2GB的RAM內存。特別是當我用ajax上傳器上傳大文件(100mb-400mb)時,以及在我打開許多圖像(例如網頁上的總共16mb圖像)時也會發生這種情況。firefox高內存(RAM)使用情況,如何用javascript免費?
問題是,即使上傳完成後或關閉圖像頁後內存沒有變得免費,Firefox仍然有2gb的內存。 有沒有一種方法從JavaScript使Firefox的內存,例如,當上傳完成或圖像加載或關閉後?
編輯 從about:memory
: 1,172.03 MB(100.0%) - 明確
├──1,000.00MB(85.32%) - JS
│├────863.97MB( 73.72%) - 倉([系統首席],0x5083000)
││├──819.31MB(69.91%)──串字符
我哪有空字符串字符,我很確定這是在文件被存入內存然後用ajax上傳的時候出現的?
編輯2
這裏是recrusive功能導致此內存使用情況:
function uploadAjax(file, startByte, index)
{
if(startByte==0)
{
$('#progress'+index).html(' ').progressbar("destroy").progressbar();
$('#asyncuploadsingle'+index).attr('disabled', true);
}
var size = file.size;
var chunkSize = 2097152;//2 megabyte
var endByte = chunkSize + startByte;
var isLast = (size - endByte <= 0);
var chunk = file;
var xhr = new XMLHttpRequest();//prepare xhr for upload
var chunkNum = endByte/chunkSize;
if(chunkSize == 0)//no divide
{
chunk = file;
isLast = true;
}
else if(file.mozSlice) // moz slice
{
chunk = file.mozSlice(startByte, endByte);
}
else if(file.webkitSlice) //webkit slice
{
chunk = file.webkitSlice(startByte, endByte);
}
else if(file.slice) // w3c slice
{
chunk = file.slice(startByte, chunkSize);
}
else
{
chunk = file;
isLast = true;
}
//progress function, with ajax upload progress can be monitored
xhr.upload.addEventListener('progress', function(e)
{
if (e.lengthComputable)
{
var perc = Math.round((e.loaded + chunkNum * chunkSize - chunkSize) * 100/size);
//console.log(perc+':'+index);
$('#progress'+index).progressbar("option", "value", perc);
}
}, false);
xhr.upload.onabort=function(e) {
finishUp(index,'Aborted');
};
xhr.upload.addEventListener('error', function(e){
finishUp(index, this.responseText+'--->'+name);
}, false);
xhr.onreadystatechange=function()
{
if(this.readyState == 4 && this.status == 200)
{
try
{
var ret = JSON.parse(this.responseText);
if(isLast)
{
finishUp(index,'');
}
else if(ret.status == 'error')
{
throw ret.info;
}
else
{
uploadAjax(file, endByte, index);
}
}
catch(err)
{
finishUp(index, err);
}
delete chunk;
}
};
var path = get_final_path();
var url = "filetransfer/uploadfiles.php?ax-file-name="+encodeURIComponent(file.name)+"&ax-file-path="+encodeURIComponent(path)+'&ax-start-byte='+startByte;
xhr.open("POST", url, true);
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');//header
xhr.setRequestHeader('Content-Type', 'application/octet-stream');//generic stream header
/*var reader = new FileReader();
reader.onload = function(evt) {
xhr.sendAsBinary(evt.target.result);
};
reader.readAsBinaryString(chunk);
*/
xhr.send(chunk);
return xhr;
}
在任何點處,以優化它或在釋放對象?
你試過關閉標籤?什麼版本? – nhahtdh
不幸的不是。你可以訪問'about:memory',但就是這樣。 –
Ajax文件上傳器?現在這聽起來非常有趣(在這裏諷刺)。至於你的問題:不可能的。 – freakish