Skip to content

Memory leak with multiple removed handlers on the same element #71

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

Closed
phillipskevin opened this issue Apr 26, 2017 · 1 comment · Fixed by #67
Closed

Memory leak with multiple removed handlers on the same element #71

phillipskevin opened this issue Apr 26, 2017 · 1 comment · Fixed by #67
Assignees

Comments

@phillipskevin
Copy link
Contributor

phillipskevin commented Apr 26, 2017

Due to the way the removed event handler is set and cleaned up, the last registered removed event will always be the one that is called and then removed. This causes a memory leak since the second handler is never turned off().

Here is an example:

var $el = $("<div>");

var teardownOne = function() { ... }; // this will be called
var teardownTwo = function() { ... }; // this will not be called

domEvents.addEventListener.call($el[0], "removed", teardownOne);
domEvents.addEventListener.call($el[0], "removed", teardownTwo);

domEvents.removeEventListener.call($el[0], "removed", teardownOne);

...
$el.remove();
@phillipskevin phillipskevin self-assigned this Apr 26, 2017
@phillipskevin
Copy link
Contributor Author

This is another part of canjs/canjs#3147.

@phillipskevin phillipskevin changed the title Memory leak with multiple event handlers on the same element Memory leak with multiple removed handlers on the same element Apr 26, 2017
@phillipskevin phillipskevin changed the title Memory leak with multiple removed handlers on the same element Memory leak with multiple removed handlers on the same element Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant