谷歌浏览器扩展中的垃圾收集

发布于 2024-11-02 18:17:33 字数 647 浏览 1 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-11-09 18:17:33

在其他浏览器中也观察到使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文