diff --git a/src/canvas.class.js b/src/canvas.class.js index fa83cb4808c..12c848fe49c 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -1555,7 +1555,10 @@ this.removeListeners(); wrapper.removeChild(this.upperCanvasEl); wrapper.removeChild(this.lowerCanvasEl); - delete this.upperCanvasEl; + this.upperCanvasEl = null; + this.cacheCanvasEl = null; + this.contextCache = null; + this.contextTop = null; if (wrapper.parentNode) { wrapper.parentNode.replaceChild(this.lowerCanvasEl, this.wrapperEl); } diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index b6851277e26..6bd78f44ea8 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -1662,6 +1662,11 @@ * @chainable */ dispose: function () { + // cancel eventually ongoing renders + if (this.isRendering) { + fabric.util.cancelAnimFrame(this.isRendering); + this.isRendering = 0; + } this.forEachObject(function(object) { object.dispose && object.dispose(); }); @@ -1670,7 +1675,7 @@ this.overlayImage = null; this._iTextInstances = null; this.lowerCanvasEl = null; - this.cacheCanvasEl = null; + this.contextContainer = null; return this; }, diff --git a/test/unit/canvas.js b/test/unit/canvas.js index 243093f20b4..2fe145ccd5a 100644 --- a/test/unit/canvas.js +++ b/test/unit/canvas.js @@ -1751,6 +1751,9 @@ } assert.equal(canvas.wrapperEl, null, 'wrapperEl should be deleted'); assert.equal(canvas.upperCanvasEl, null, 'upperCanvas should be deleted'); + assert.equal(canvas.cacheCanvasEl, null, 'cacheCanvasEl should be deleted'); + assert.equal(canvas.contextTop, null, 'contextTop should be deleted'); + assert.equal(canvas.contextCache, null, 'contextCache should be deleted'); }); // QUnit.test('dispose', function(assert) { diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index 5eb0cf29f80..004ffc8222f 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -1428,6 +1428,7 @@ canvas2.dispose(); assert.equal(canvas2.getObjects().length, 0, 'dispose should clear canvas'); assert.equal(canvas2.lowerCanvasEl, null, 'dispose should clear lowerCanvasEl'); + assert.equal(canvas2.contextContainer, null, 'dispose should clear contextContainer'); }); QUnit.test('clone', function(assert) {