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

Commit 396566f

Browse files
committed
fix($rootScope): fix potential memory leak when removing scope listeners
When removing listeners they are removed from the array but the array size is not changed until the event is fired again. If the event is never fired but listeners are added/removed then the array will continue growing. By changing the listener removal to `delete` the array entry instead of setting it to `null` browsers can potentially deallocate the memory for the entry. Fixes #16135
1 parent d1e971b commit 396566f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ng/rootScope.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,10 @@ function $RootScopeProvider() {
11801180
return function() {
11811181
var indexOfListener = namedListeners.indexOf(listener);
11821182
if (indexOfListener !== -1) {
1183-
namedListeners[indexOfListener] = null;
1183+
// Use delete in the hope of the browser deallocating the memory for the array entry,
1184+
// while not shifting the array indexes of other listeners.
1185+
// See issue https://github.com/angular/angular.js/issues/16135
1186+
delete namedListeners[indexOfListener];
11841187
decrementListenerCount(self, 1, name);
11851188
}
11861189
};

0 commit comments

Comments
 (0)