Skip to content

Commit

Permalink
Fix chat memory leaks (smogon#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
KamilaBorowska authored and Zarel committed Aug 10, 2016
1 parent bba7941 commit 49fc993
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 5 additions & 7 deletions js/client-chat-tournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
top: position.top
});

var isMouseDown = false;
// Note: Origin starts from the top right instead of the top left here,
// because when a battle room is opened, the left side moves but the right doesn't,
// so we have to use the right side to keep the element in the same location.
Expand All @@ -64,11 +63,8 @@
$element.on('mousedown', function (e) {
innerX = e.pageX + ($element.parent().width() - $element.width() - this.offsetLeft);
innerY = e.pageY - this.offsetTop;
isMouseDown = true;
});

$(document).on('mousemove', function (e) {
if (isMouseDown) {
function mouseMoveCallback(e) {
position.right = innerX - e.pageX;
position.top = e.pageY - innerY;
delete position.isDefault;
Expand All @@ -78,8 +74,10 @@
top: position.top
});
}
}).on('mouseup', function () {
isMouseDown = false;
$(document).on('mousemove', mouseMoveCallback)
.on('mouseup', function () {
$(document).off('mousemove', mouseMoveCallback);
});
});
}

Expand Down
10 changes: 10 additions & 0 deletions js/client-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@
if (autoscroll) {
this.$chatFrame.scrollTop(this.$chat.height());
}
},
destroy: function () {
app.user.off('change', this.updateUser, this);
Room.prototype.destroy.call(this);
}
}, {
toggleFormatChar: function (textbox, formatChar) {
Expand Down Expand Up @@ -1443,6 +1447,12 @@
} else if (message.substr(0, 10) === '/announce ' || message.substr(0, 1) !== '/') {
Storage.logChat(this.id, '' + name + ': ' + message);
}
},
destroy: function () {
if (this.tournamentBox) {
app.user.off('saveteams', this.tournamentBox.updateTeams, this.tournamentBox);
}
ConsoleRoom.prototype.destroy.call(this);
}
}, {
getTimestamp: function (section, msgTime) {
Expand Down

0 comments on commit 49fc993

Please sign in to comment.