JavaScript侦听器不断增加

编程入门 行业动态 更新时间:2024-10-28 14:24:05
本文介绍了JavaScript侦听器不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我实现了一个Web应用程序,并使用Google开发人员工具监控了性能.我注意到侦听器不断增加,堆也在增加.

I implemented a web application and monitored the performance with the google developer tools. I notice that the listeners keep increasing and so is the heap.

听众正在增加的部分看起来像这样

The part where the listeners are increasing looks something like this

let ival = $interval(function () { $http.get('someurl') // this call is actually done through a service, don't know if that matters }, 1000)

我会理解堆是否由于垃圾收集器未收集到的某些数据而增长,但我不明白为什么侦听器在增加?

I would understand if the heap grows because of some data not beeing collected by the garbage collector but I don't understand why the listeners are increasing?

这是一个可重现的最小示例:

Here is a reproducable, minimal example:

index.html文件:

The index.html file:

<!doctype html> <html ng-app="exampleModule"> <head> <script src="ajax.googleapis/ajax/libs/angularjs/1.6.6/angular.min.js"></script> <script src="script.js"></script> </head> <body> <div ng-controller="someController"> </div> </body> </html>

还有script.js文件:

And the script.js file:

angular.module("exampleModule", []) .controller("someController", [ "$http", "$interval", function ($http, $interval) { $interval(function () { $http.get('script.js') }, 1000) }])

观看表演时的结果与上图相同.您应该使用简单的网络服务器来发出GET请求.

The results when you watch the performance are the same as in the picture above. You should use a simple webserver in order to make the GET request.

推荐答案

根据此问题,更具体地说是此评论,是由在录制性能时间表时,Chrome不会垃圾回收监听器.

According to this issue, more specifically this comment, it's caused by Chrome not garbage collecting listeners during recording of the performance timeline.

更多推荐

JavaScript侦听器不断增加

本文发布于:2023-10-28 13:57:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536823.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!