fix: fixes canvas resources release (useful for getting rid of the canvas memory leaks on iOS)

This commit is contained in:
Dmitry Zarva 2022-10-31 20:27:32 +03:00
parent 578191d5d4
commit e7b2bd6d15
6 changed files with 20 additions and 1 deletions

View File

@ -23,6 +23,7 @@ function getDevicePixelRatio() {
1;
return devicePixelRatio / backingStoreRatio;
})();
Util.releaseCanvas(canvas);
return _pixelRatio;
}

View File

@ -468,6 +468,11 @@ export class Layer extends Container<Group | Shape> {
}
}
destroy(): this {
Util.releaseCanvas(this.getNativeCanvasElement(), this.getCanvas()._canvas);
return super.destroy();
}
hitGraphEnabled: GetSet<boolean, this>;
clearBeforeDraw: GetSet<boolean, this>;

View File

@ -278,6 +278,9 @@ export class Stage extends Container<Layer> {
if (index > -1) {
stages.splice(index, 1);
}
Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas)
return this;
}
/**

View File

@ -957,4 +957,10 @@ export const Util = {
return evt.changedTouches[0].identifier;
}
},
releaseCanvas(...canvases: HTMLCanvasElement[]) {
canvases.forEach(c => {
c.width = 0;
c.height = 0;
})
}
};

View File

@ -197,7 +197,7 @@ export const Kaleidoscope: Filter = function (imageData) {
var scratchData = tempCanvas
.getContext('2d')
.getImageData(0, 0, xSize, ySize);
Util.releaseCanvas(tempCanvas);
// Convert thhe original to polar coordinates
ToPolar(imageData, scratchData, {
polarCenterX: xSize / 2,

View File

@ -533,6 +533,10 @@ export class TextPath extends Shape<TextPathConfig> {
height: maxY - minY + fontSize,
};
}
destroy(): this {
Util.releaseCanvas(this.dummyCanvas);
return super.destroy();
}
fontFamily: GetSet<string, this>;
fontSize: GetSet<number, this>;