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

fix($rootScope): deallocate $$listeners array when empty #16277

Closed
wants to merge 1 commit into from

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Oct 15, 2017

I think making $$listenerCount[name] and $$listeners[name] behave the same makes sense. Today the $$listeners array might also grow and never be cleaned up unless an event is fired (#16135), however if there are no listeners then even firing an event won't clean it up, but this will in that case.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I am not super keen on this change. It will make destroying scopes and adding a listener for an event whose listeners were previously removed (which is exactly what caused the leak in #16135) a little less efficient. And both of these operations are quite frequent. On the other side, it will save one empty array worth of memory for the rare case that an event is subscribed and then unsubscribed to (forever) 😕

Did I miss something?

@@ -1375,6 +1374,7 @@ function $RootScopeProvider() {

if (current.$$listenerCount[name] === 0) {
delete current.$$listenerCount[name];
delete current.$$listeners[name];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue brought up is that $$listeners and $$listenerCount often do not have the same lifetime. $$listenerCount will reach 0 only when this scope and all child scopes have no listeners. I think that might convince me that this PR is no good as-is. But I still thinking cleaning up $$listeners when empty might be a decent idea. TBD...

@Narretz Narretz added this to the Ice Box milestone Oct 17, 2017
@jbedard
Copy link
Contributor Author

jbedard commented Nov 22, 2017

Now that the array is resized on event removal I don't think this is as important because the array will actually shrink when events are removed. I'm going to close this for now but let me know if anyone disagrees or wants to look into this more...

@jbedard jbedard closed this Nov 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants