removed references to context when disposing (#4846)

* removed references to context
* improved test
* try fix error
This commit is contained in:
Andrea Bogazzi 2018-03-22 12:35:12 +01:00 committed by GitHub
parent 17386fc240
commit 682eac4545
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 2 deletions

View file

@ -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);
}

View file

@ -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;
},

View file

@ -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) {

View file

@ -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) {