Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript google chrome扩展中的垃圾收集_Javascript_Ajax_Garbage Collection_Google Chrome Extension_Xmlhttprequest - Fatal编程技术网

Javascript google chrome扩展中的垃圾收集

Javascript google chrome扩展中的垃圾收集,javascript,ajax,garbage-collection,google-chrome-extension,xmlhttprequest,Javascript,Ajax,Garbage Collection,Google Chrome Extension,Xmlhttprequest,我正在开发一个GoogleChrome扩展,它有javascript代码,可以定期发出xhr请求。我意识到,随着时间的推移,进程占用的RAM量开始增加。我不确定这是因为xhr请求没有被垃圾收集,还是因为google chrome保留了xhr请求的响应而没有清除它。以下是我的一些代码: var locationx = "http://www.example.com"; var newxhrx = new XMLHttpRequest() newxhrx.startedOn = new Date

我正在开发一个GoogleChrome扩展,它有javascript代码,可以定期发出xhr请求。我意识到,随着时间的推移,进程占用的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保存了响应?这可以修复吗?如何修复?

在其他浏览器中也可以观察到使用AJAX调用时内存使用量的增长


谢谢!我看了一下谷歌链接。您所需要做的就是使用“delete”命令,因为将其设置为null意味着您可能无法对其进行垃圾收集。