2
我正在开发一个google-chrome扩展,它具有定期发出xhr请求的JavaScript代码。我意识到随着时间的推移,进程占用的RAM数量开始增加。我不确定是否这是由于xhr请求没有被垃圾收集的事实,或者是因为google-chrome保留了xhr请求的响应并且没有被除去。以下是我的部分代码:谷歌浏览器扩展中的垃圾收集
var locationx = "http://www.example.com";
var newxhrx = new XMLHttpRequest()
newxhrx.startedOn = new Date().getTime()
try {
newxhrx.open("GET", locationx, true)
newxhrx.followRedirects = false
newxhrx.send(null)
} catch(e1){
alert('No internet connection')
}
newxhrx = null;
locationx = null;
如果我查看chrome开发人员工具中的“网络”部分。我看到该页面被多次调用,并且这些部分的响应不会被删除。这是由于JavaScript内存泄漏还是因为google-chrome保存响应而导致的问题?这可以解决,如何?
谢谢!我看着谷歌链接。所有你需要做的就是使用“delete”命令,因为将它设置为null意味着你冒着chrome而不是垃圾收集它的风险。 – 2011-04-21 19:29:04