Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c9e18c2

Browse files
committed
fix($rootScope): deallocate $$listeners array when empty
1 parent 55ba449 commit c9e18c2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ng/rootScope.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ function $RootScopeProvider() {
955955
// Disable listeners, watchers and apply/digest methods
956956
this.$destroy = this.$digest = this.$apply = this.$evalAsync = this.$applyAsync = noop;
957957
this.$on = this.$watch = this.$watchGroup = function() { return noop; };
958-
this.$$listeners = {};
959958

960959
// Disconnect the next sibling to prevent `cleanUpScope` destroying those too
961960
this.$$nextSibling = null;
@@ -1364,6 +1363,7 @@ function $RootScopeProvider() {
13641363

13651364
if (current.$$listenerCount[name] === 0) {
13661365
delete current.$$listenerCount[name];
1366+
delete current.$$listeners[name];
13671367
}
13681368
} while ((current = current.$parent));
13691369
}

test/ng/rootScopeSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,26 @@ describe('Scope', function() {
25622562
expect(secondListener).not.toHaveBeenCalled();
25632563
});
25642564
});
2565+
2566+
2567+
it('should deallocate the $$listenerCount entry when reaching 0', inject(function($rootScope) {
2568+
var child = $rootScope.$new();
2569+
2570+
child.$on('abc', noop)();
2571+
2572+
expect('abc' in $rootScope.$$listenerCount).toBe(false);
2573+
expect('abc' in child.$$listenerCount).toBe(false);
2574+
}));
2575+
2576+
2577+
it('should deallocate the $$listeners entry when empty', inject(function($rootScope) {
2578+
var child = $rootScope.$new();
2579+
2580+
child.$on('abc', noop)();
2581+
2582+
expect('abc' in $rootScope.$$listeners).toBe(false);
2583+
expect('abc' in child.$$listeners).toBe(false);
2584+
}));
25652585
});
25662586
});
25672587

0 commit comments

Comments
 (0)