Skip to content

Instantly share code, notes, and snippets.

@Identity-labs
Created June 22, 2016 12:01
Show Gist options
  • Save Identity-labs/69c0348aa8e1daa991532b4d40f3bef8 to your computer and use it in GitHub Desktop.
Save Identity-labs/69c0348aa8e1daa991532b4d40f3bef8 to your computer and use it in GitHub Desktop.
angularjs, debug watchers growing in app
$rootScope.countWatchers = function () {
var q = [$rootScope], watchers = 0, scope;
while (q.length > 0) {
scope = q.pop();
if (scope.$$watchers) {
watchers += scope.$$watchers.length;
}
if (scope.$$childHead) {
q.push(scope.$$childHead);
}
if (scope.$$nextSibling) {
q.push(scope.$$nextSibling);
}
}
window.console.log(watchers);
};
setInterval(function(){
$rootScope.countWatchers();
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment