-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Auto-cleanup component event listeners on the document and other components #1544
Comments
I was about to open a new thread about this issue and thankfully, you were already on that. I think that your proposed solution is not backwards compatible. Plugins that used to set listeners on other components with the old-fashioned way won't work until they get updated and this might break players using old plugins. I am also concerned about the semantics of the setters. It starts with I was thinking if you could use the |
I'm not sure I'm clear on your concerns, but the old way for adding event listeners to the component would not change.
In the Plugins that already set listeners on other components use this pattern:
That pattern will still work as well. |
What I was thinking about my first concern was the plugins that used to set the listeners using the current pattern will still have the mentioned problem and they won't get the fix until they update their setters. About the semantics, I will give you a more clear example. Why use the |
I don't think there's any way we can fix this in reverse for plugins without overcomplicating the vjs.on function, so it will have to just be a feature moving forward. It's a convenience feature anyway, so hopefully most plugins are already good about cleaning up listeners.
Interesting. It sounds like it'd be good to get some other opinions on this. To me it reads quite nicely.
ComponentA on ComponentB's click event should do something. Especially when
The main point of this feature is to clean up listeners that componentA puts on other components when componentA gets disposed. Currently we just use |
Alright then, agreed. :) |
…mponents. closes videojs#1544 Automatically cleans up listeners when either component is diposed.
This feature was completed by #1588. |
We've had a few issues with event listeners not getting cleaned up appropriately when components are disposed of. A component will currently automatically clean up any listeners on its own element, however it won't automatically clean up listeners it has on the document or other components. After a discussion with @mmcc, we think it'd be good (and not too much magic) to clean up the other instances as well.
The current component event listener functions look like:
We would add the following APIs.
The new APIs would store records of the event listeners being added by a component (component X) to the doc/other components, and attempt to remove them when component X is disposed of.
In the case of other components, component X should listen for the dispose event of component Y, and remove any listeners on Y when it is disposed. This will prevent memory leaks where Y is prevented from being garbage collected.
We're assuming document will never be 'disposed'. The potential for memory leaks is why we can't make this possible for other generic elements. We couldn't know when an element is permanently removed from the document and release the reference to it.
Related Issues: #1475, #1476
The text was updated successfully, but these errors were encountered: