Skip to content

Commit

Permalink
Reduce leaks in NODEJS continue canvas creations (fabricjs#4471)
Browse files Browse the repository at this point in the history
* reduce leaks in node

* fix test
  • Loading branch information
asturur authored Nov 19, 2017
1 parent c1ef1e8 commit 57d3a63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,6 @@
* @chainable
*/
dispose: function () {
fabric.StaticCanvas.prototype.dispose.call(this);
var wrapper = this.wrapperEl;
this.removeListeners();
wrapper.removeChild(this.upperCanvasEl);
Expand All @@ -1548,6 +1547,7 @@
wrapper.parentNode.replaceChild(this.lowerCanvasEl, this.wrapperEl);
}
delete this.wrapperEl;
fabric.StaticCanvas.prototype.dispose.call(this);
return this;
},

Expand Down
7 changes: 6 additions & 1 deletion src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,12 @@
* @chainable
*/
dispose: function () {
this.clear();
this._objects.length = 0;
this.backgroundImage = null;
this.overlayImage = null;
this._iTextInstances = null;
this.lowerCanvasEl = null;
this.cacheCanvasEl = null;
return this;
},

Expand Down
12 changes: 7 additions & 5 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -1313,11 +1313,13 @@
assert.equal(canvas.toString(), '#<fabric.Canvas (1): { objects: 1 }>');
});

QUnit.test('dispose', function(assert) {
assert.ok(typeof canvas.dispose === 'function');
canvas.add(makeRect(), makeRect(), makeRect());
canvas.dispose();
assert.equal(canvas.getObjects().length, 0, 'dispose should clear canvas');
QUnit.test('dispose clear references', function(assert) {
var canvas2 = new fabric.Canvas();
assert.ok(typeof canvas2.dispose === 'function');
canvas2.add(makeRect(), makeRect(), makeRect());
canvas2.dispose();
assert.equal(canvas2.getObjects().length, 0, 'dispose should clear canvas');
assert.equal(canvas2.lowerCanvasEl, null, 'dispose should clear lowerCanvasEl');
});

QUnit.test('clone', function(assert) {
Expand Down

0 comments on commit 57d3a63

Please sign in to comment.