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

fix #684 memory leaks issues after destroy. #700

Merged
merged 1 commit into from
Nov 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/js/plyr.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,11 @@
}

// Unbind event
/*function _off(element, events, callback, useCapture) {
function _off(element, events, callback, useCapture) {
if (element) {
_toggleListener(element, events, callback, false, useCapture);
}
}*/
}

// Trigger event
function _event(element, type, bubbles, properties) {
Expand Down Expand Up @@ -2931,6 +2931,10 @@
}
}

function onBodyClick() {
_toggleClass(_getElement('.' + config.classes.tabFocus), config.classes.tabFocus, false);
}

// Listen for control events
function _controlListeners() {
// IE doesn't support input event, so we fallback to change
Expand Down Expand Up @@ -3145,9 +3149,7 @@
checkTabFocus(focused);
}
});
_on(document.body, "click", function() {
_toggleClass(_getElement("." + config.classes.tabFocus), config.classes.tabFocus, false);
});
_on(document.body, "click", onBodyClick);
for (var button in plyr.buttons) {
var element = plyr.buttons[button];

Expand Down Expand Up @@ -3429,9 +3431,15 @@
// Replace the container with the original element provided
plyr.container.parentNode.replaceChild(original, plyr.container);

// Free container in order for GC to remove it and prevent memory leaks due to added events
plyr.container = null;

// Allow overflow (set on fullscreen)
document.body.style.overflow = "";

//remove events
_off(document.body, 'click', onBodyClick);

// Event
_triggerEvent(original, "destroyed", true);
}
Expand Down