-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOMRenderer listener leaks #378
Comments
|
@alexanderGugel I'm not sure I follow everything you said: (stated in the form of questions)
Correct, most elements will not have an event listener, but any where we call
Understood, but there isn't a
You lost me... As long as the element stays associated with the same
This is only relative to the level, and has no relation to which parent it is under.. ?
The logic to remove DOM event listeners? I probably made this sound a little more catastrophic than I needed and will correct that. Was simply trying to say that the listeners are never removed so if the DOM element was ever destroyed it wouldn't be GC'd because of the listener references. |
No. We use event delegation in most cases. The event listener is only being added once per event type. E.g. if I add an event listener for "click" to node1 and node2, there will only be one listener.
Needs to be merged in: https://github.com/Famous/engine/pull/318/files
We are using event delegation. Listening for a new event doesn't necessarily mean adding a new event listener. If the event bubbles, we simply catch it as it bubbles up to the root element, where there is only one event listener per type. What you say is only true for non-bubbling events (such as
The general logic needed for cleaning up the DOMElement, including - but not limited to - removing event listeners that have been attached to the element.
You raised a couple of good points that are worth being discussed. Currently the documentation on how we are actually attaching event listeners, why we do it (performance, GC) etc. is... non existent. I apologize for any confusion arising from that. I'm gonna write a blog post or something about that. AFAIK this is only an issue in ancient versions of IE. If we would remove them from the DOM, we probably also wouldn't have to clean them up. I will elaborate on my points on Monday. I just wanted to give a quick response. |
@alexanderGugel the article you shared is actually really good. I did not realize that javascript only counts the references to the object, and not the references from the object, before collecting. Closing as you are correct even if the element is removed, any listener reference would not prevent the collection. |
Currently there is no facility which removes listeners from the actual DOM element. When we subscribe to a DOM event, the DOMRenderer will add a listener by:
If the associated node is removed/dismounted and the underlying DOM element is freed, we will never stop listening to the subscribed events on that element.
The text was updated successfully, but these errors were encountered: