【发布时间】:2011-04-22 02:57:55
【问题描述】:
我正在开发一个 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 保存响应?这可以解决吗?如何解决?
【问题讨论】:
标签: javascript ajax garbage-collection google-chrome-extension xmlhttprequest