Commit 53f54248 authored by Neil Fraser's avatar Neil Fraser

Skc memory leaks (PR #159)

parent e8f1de3b
This diff is collapsed.
......@@ -59,7 +59,7 @@ Blockly.Flyout = function(workspaceOptions) {
this.RTL = !!workspaceOptions.RTL;
/**
* Opaque data that can be passed to removeChangeListener.
* Opaque data that can be passed to Blockly.unbindEvent_.
* @type {Array.<!Array>}
* @private
*/
......@@ -145,14 +145,14 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) {
this.hide();
this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_,
'wheel', this, this.wheel_));
this.eventWrappers_.concat(
Array.prototype.push.apply(this.eventWrappers_,
Blockly.bindEvent_(this.svgGroup_, 'wheel', this, this.wheel_));
Array.prototype.push.apply(this.eventWrappers_,
Blockly.bindEvent_(this.targetWorkspace_.getCanvas(),
'blocklyWorkspaceChange', this, this.filterForCapacity_));
// Dragging the flyout up and down.
this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_,
'mousedown', this, this.onMouseDown_));
Array.prototype.push.apply(this.eventWrappers_,
Blockly.bindEvent_(this.svgGroup_, 'mousedown', this, this.onMouseDown_));
};
/**
......@@ -162,12 +162,15 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) {
Blockly.Flyout.prototype.dispose = function() {
this.hide();
Blockly.unbindEvent_(this.eventWrappers_);
this.eventWrappers_.length = 0;
if (this.scrollbar_) {
this.scrollbar_.dispose();
this.scrollbar_ = null;
}
this.workspace_ = null;
if (this.workspace_) {
this.workspace_.targetWorkspace = null;
this.workspace_.dispose();
this.workspace_ = null;
}
if (this.svgGroup_) {
goog.dom.removeNode(this.svgGroup_);
this.svgGroup_ = null;
......
......@@ -53,8 +53,6 @@ Blockly.ScrollbarPair = function(workspace) {
* Unlink from all DOM elements to prevent memory leaks.
*/
Blockly.ScrollbarPair.prototype.dispose = function() {
Blockly.unbindEvent_(this.onResizeWrapper_);
this.onResizeWrapper_ = null;
goog.dom.removeNode(this.corner_);
this.corner_ = null;
this.workspace_ = null;
......@@ -190,10 +188,6 @@ if (goog.events.BrowserFeature.TOUCH_ENABLED) {
*/
Blockly.Scrollbar.prototype.dispose = function() {
this.onMouseUpKnob_();
if (this.onResizeWrapper_) {
Blockly.unbindEvent_(this.onResizeWrapper_);
this.onResizeWrapper_ = null;
}
Blockly.unbindEvent_(this.onMouseDownBarWrapper_);
this.onMouseDownBarWrapper_ = null;
Blockly.unbindEvent_(this.onMouseDownKnobWrapper_);
......
......@@ -147,6 +147,7 @@ Blockly.Toolbox.prototype.dispose = function() {
this.flyout_.dispose();
this.tree_.dispose();
goog.dom.removeNode(this.HtmlDiv);
this.workspace_ = null;
};
/**
......
......@@ -52,12 +52,20 @@ Blockly.WorkspaceSvg = function(options) {
this.setMetrics = options.setMetrics;
Blockly.ConnectionDB.init(this);
/**
* Database of pre-loaded sounds.
* @private
* @const
*/
this.SOUNDS_ = Object.create(null);
/**
* Opaque data that can be passed to Blockly.unbindEvent_.
* @type {Array.<!Array>}
* @private
*/
this.eventWrappers_ = [];
};
goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
......@@ -187,6 +195,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
Blockly.WorkspaceSvg.prototype.dispose = function() {
// Stop rerendering.
this.rendered = false;
Blockly.unbindEvent_(this.eventWrappers_);
Blockly.WorkspaceSvg.superClass_.dispose.call(this);
if (this.svgGroup_) {
goog.dom.removeNode(this.svgGroup_);
......@@ -206,9 +215,13 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
this.trashcan.dispose();
this.trashcan = null;
}
if (this.zoomControls) {
this.zoomControls.dispose();
this.zoomControls = null;
if (this.scrollbar) {
this.scrollbar.dispose();
this.scrollbar = null;
}
if (this.zoomControls_) {
this.zoomControls_.dispose();
this.zoomControls_ = null;
}
if (!this.options.parentWorkspace) {
// Top-most workspace. Dispose of the SVG too.
......@@ -221,6 +234,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
* @private
*/
Blockly.WorkspaceSvg.prototype.addTrashcan_ = function() {
/** @type {Blockly.Trashcan} */
this.trashcan = new Blockly.Trashcan(this);
var svgTrashcan = this.trashcan.createDom();
this.svgGroup_.insertBefore(svgTrashcan, this.svgBlockCanvas_);
......@@ -232,10 +246,11 @@ Blockly.WorkspaceSvg.prototype.addTrashcan_ = function() {
* @private
*/
Blockly.WorkspaceSvg.prototype.addZoomControls_ = function() {
this.zoomControls = new Blockly.ZoomControls(this);
var svgZoomControls = this.zoomControls.createDom();
/** @type {Blockly.ZoomControls} */
this.zoomControls_ = new Blockly.ZoomControls(this);
var svgZoomControls = this.zoomControls_.createDom();
this.svgGroup_.appendChild(svgZoomControls);
this.zoomControls.init();
this.zoomControls_.init();
};
/**
......@@ -247,6 +262,7 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function() {
parentWorkspace: this,
RTL: this.RTL
};
/** @type {Blockly.Flyout} */
this.flyout_ = new Blockly.Flyout(workspaceOptions);
this.flyout_.autoClose = false;
var svgFlyout = this.flyout_.createDom();
......@@ -266,8 +282,8 @@ Blockly.WorkspaceSvg.prototype.resize = function() {
if (this.trashcan) {
this.trashcan.position();
}
if (this.zoomControls) {
this.zoomControls.position();
if (this.zoomControls_) {
this.zoomControls_.position();
}
if (this.scrollbar) {
this.scrollbar.resize();
......@@ -811,8 +827,10 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) {
* removeChangeListener.
*/
Blockly.WorkspaceSvg.prototype.addChangeListener = function(func) {
return Blockly.bindEvent_(this.getCanvas(),
var wrapper = Blockly.bindEvent_(this.getCanvas(),
'blocklyWorkspaceChange', null, func);
Array.prototype.push.apply(this.eventWrappers_, wrapper);
return wrapper;
};
/**
......@@ -821,6 +839,10 @@ Blockly.WorkspaceSvg.prototype.addChangeListener = function(func) {
*/
Blockly.WorkspaceSvg.prototype.removeChangeListener = function(bindData) {
Blockly.unbindEvent_(bindData);
var i = this.eventWrappers_.indexOf(bindData);
if (i != -1) {
this.eventWrappers_.splice(i, 1);
}
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment