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

Commit b442535

Browse files
committed
fix($rootScope): deallocate $$listeners array when empty
1 parent 00936ad commit b442535

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;
@@ -1375,6 +1374,7 @@ function $RootScopeProvider() {
13751374

13761375
if (current.$$listenerCount[name] === 0) {
13771376
delete current.$$listenerCount[name];
1377+
delete current.$$listeners[name];
13781378
}
13791379
} while ((current = current.$parent));
13801380
}

test/ng/rootScopeSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,26 @@ describe('Scope', function() {
23642364
expect($rootScope.$$listenerCount).toEqual({abc: 1});
23652365
expect(child.$$listenerCount).toEqual({abc: 1});
23662366
}));
2367+
2368+
2369+
it('should deallocate the $$listenerCount entry when reaching 0', inject(function($rootScope) {
2370+
var child = $rootScope.$new();
2371+
2372+
child.$on('abc', noop)();
2373+
2374+
expect('abc' in $rootScope.$$listenerCount).toBe(false);
2375+
expect('abc' in child.$$listenerCount).toBe(false);
2376+
}));
2377+
2378+
2379+
it('should deallocate the $$listeners entry when empty', inject(function($rootScope) {
2380+
var child = $rootScope.$new();
2381+
2382+
child.$on('abc', noop)();
2383+
2384+
expect('abc' in $rootScope.$$listeners).toBe(false);
2385+
expect('abc' in child.$$listeners).toBe(false);
2386+
}));
23672387
});
23682388
});
23692389

0 commit comments

Comments
 (0)