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
listenToOnce creates unexpected memory leak in _listeningTo object #3226
Comments
+1 |
@jashkenas and @akre54, Is there any chance of discussion about this? |
Sure -- but I'd need to take a look at it first ;) |
Here's a requirebin that reproduces the bug http://requirebin.com/?gist=6e01165ef5e153469326 |
I whipped up a failing unit test that demonstrates this issue over in #3341. |
This solution looks right. @malte-wessel @jmeas can you combine the failing test and the fix into a single PR? |
Yup, I'll update my PR. |
Closed in favor of #3341 |
When using
listenToOnce
, I’d expect that post-trigger, I’d be free of associations between my listener and my object, much like when callingonce
. However, even though the event listener cleans up, the object reference is still maintained through the_listeningTo
object. This has potential to create unexpected memory leaks.An Example
A parent view creates a child view that acts as a modal. I have the parent view
listenToOnce
for a close event on the children views. This is the only event the parent is listening for on the child. That close event fires once and the parent view callback is satisfied. The child view has.remove()
performed and everything is thought to be cleaned up. The child view is not able to be gc’d though because the parent still has a reference in_listeningTo
. In a case of a long living parent view, this can become a incremental leak as I perform more view creations.As a normal backbone user, I have no idea that a reference is maintained to the object being listened to. This would be my expectation when there are no more events being watched. I don't know that I need to perform
stopListening
manually.Proposal
Differentiate
listenToOnce
fromlistenTo
. LetlistenToOnce
perform astopListening(childView, event)
when the callback is executed… thereby removing the association if it was the only event being watched.My very inelegant solution which strikes at the crux of the problem:
Thoughts?
The text was updated successfully, but these errors were encountered: