Fix two memory leaks (#3747)

* Fix two memory leaks
This commit is contained in:
Sam El-Husseini
2020-03-13 14:49:08 -07:00
committed by GitHub
parent 877063b5bd
commit 14428a0da4
5 changed files with 30 additions and 3 deletions

View File

@@ -291,6 +291,7 @@ Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() {
// Fire a move event, so we know where to go back to for an undo.
this.fireMoveEvent_();
this.draggingBlock_.dispose(false, true);
Blockly.draggingConnections = [];
} else if (trashcan) {
// Make sure the trash can is closed.
trashcan.close();

View File

@@ -943,7 +943,8 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
// The block has already been deleted.
return;
}
Blockly.Tooltip.hide();
Blockly.Tooltip.dispose();
Blockly.Tooltip.unbindMouseEvents(this.pathObject.svgPath);
Blockly.utils.dom.startTextWidthCache();
// Save the block's workspace temporarily so we can resize the
// contents once the block is disposed.

View File

@@ -394,6 +394,7 @@ Blockly.Field.prototype.toXml = function(fieldElement) {
Blockly.Field.prototype.dispose = function() {
Blockly.DropDownDiv.hideIfOwner(this);
Blockly.WidgetDiv.hideIfOwner(this);
Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_());
if (this.mouseDownWrapper_) {
Blockly.unbindEvent_(this.mouseDownWrapper_);

View File

@@ -548,6 +548,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() {
for (var j = 0; j < this.mats_.length; j++) {
var rect = this.mats_[j];
if (rect) {
Blockly.Tooltip.unbindMouseEvents(rect);
Blockly.utils.dom.removeNode(rect);
}
}

View File

@@ -129,9 +129,9 @@ Blockly.Tooltip.createDom = function() {
* @param {!Element} element SVG element onto which tooltip is to be bound.
*/
Blockly.Tooltip.bindMouseEvents = function(element) {
Blockly.bindEvent_(element, 'mouseover', null,
element.mouseOverWrapper_ = Blockly.bindEvent_(element, 'mouseover', null,
Blockly.Tooltip.onMouseOver_);
Blockly.bindEvent_(element, 'mouseout', null,
element.mouseOutWrapper_ = Blockly.bindEvent_(element, 'mouseout', null,
Blockly.Tooltip.onMouseOut_);
// Don't use bindEvent_ for mousemove since that would create a
@@ -140,6 +140,19 @@ Blockly.Tooltip.bindMouseEvents = function(element) {
element.addEventListener('mousemove', Blockly.Tooltip.onMouseMove_, false);
};
/**
* Unbinds tooltip mouse events from the SVG element.
* @param {!Element} element SVG element onto which tooltip is bound.
*/
Blockly.Tooltip.unbindMouseEvents = function(element) {
if (!element) {
return;
}
Blockly.unbindEvent_(element.mouseOverWrapper_);
Blockly.unbindEvent_(element.mouseOutWrapper_);
element.removeEventListener('mousemove', Blockly.Tooltip.onMouseMove_);
};
/**
* Hide the tooltip if the mouse is over a different object.
* Initialize the tooltip to potentially appear for this object.
@@ -223,6 +236,16 @@ Blockly.Tooltip.onMouseMove_ = function(e) {
}
};
/**
* Dispose of the tooltip.
* @package
*/
Blockly.Tooltip.dispose = function() {
Blockly.Tooltip.element_ = null;
Blockly.Tooltip.poisonedElement_ = null;
Blockly.Tooltip.hide();
};
/**
* Hide the tooltip.
*/