谷歌浏览器扩展中的垃圾收集
我正在开发一个 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 保存响应造成的?这个问题可以解决吗?如何解决?
I am developing a google-chrome extension that has javascript code that is make xhr requests periodically. I realized that over time, the amount of RAM that the process took up started increasing. I am not sure if this is due to the fact that the xhr requests do not get garbage collected or if it is because google-chrome keeps the response of the xhr request and doesnt get rid of it. Here is some of my code:
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;
If I look at the "Network" section in the chrome developer tools. I see that the page is called multiple times and the responses do not get removed from this section. Is this problem due to a JavaScript memory leak or because of google-chrome saving the responses? Can this be fixed and how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在其他浏览器中也观察到使用 AJAX 调用时内存使用量的增长。
http://forum.jquery.com/topic/memory-leaks-with -ajax-calls
http://code.google.com/p/chromium/issues/detail?id=52411
The growth of memory usage when working with AJAX calls is observed in other browsers as well.
http://forum.jquery.com/topic/memory-leaks-with-ajax-calls
http://code.google.com/p/chromium/issues/detail?id=52411