我注意到,使用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