我正在开发一个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保存了响应?这个问题可以解决吗?如何解决?
发布于 2011-04-22 02:57:56
在其他浏览器中也可以观察到使用AJAX调用时内存使用量的增长。
http://forum.jquery.com/topic/memory-leaks-with-ajax-calls
http://code.google.com/p/chromium/issues/detail?id=52411
https://stackoverflow.com/questions/5747948
复制相似问题