我实现了一个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侦听器不断增加
发布评论