Skip to content
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

Fixing event leak when using multiple event handlers on the same element #55

Merged

Conversation

mindfreakthemon
Copy link
Contributor

Hi!

When using multiple jBone event handlers on the same element, removing the first added handler before any other will result in leaking the native event handler as to it cannot be removed anymore.

Consider the following example:

<!doctype html>
<html>
<head>
    <title>Test Leak</title>
    <script type="text/javascript" src="bower_components/jbone/dist/jbone.js"></script>
</head>
<body>
</body>
<script type="text/javascript">
    var $body = $('body');

    $body.on('mouseover.nice1', function () {});
    $body.on('mouseover.nice2', function () {});
    $body.off('mouseover.nice1');
    $body.off('mouseover.nice2');
</script>
</html>

Here we are removing the first jBone handler and after that - the second one. The first jBone handler was the one that was put into addEventListener's callback argument, but it will not call removeEventListener as to there is still another event in the events array. Removing the second handler does call removeEventListener, but it does not remove the native handler because the callback argument does not match with the one that was put into addEventListener.

kupriyanenko added a commit that referenced this pull request Oct 9, 2015
Fixing event leak when using multiple event handlers on the same element
@kupriyanenko kupriyanenko merged commit 5f1b299 into kupriyanenko:master Oct 9, 2015
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 this pull request may close these issues.

2 participants