mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
fix: fixes canvas resources release (useful for getting rid of the canvas memory leaks on iOS)
This commit is contained in:
parent
578191d5d4
commit
e7b2bd6d15
@ -23,6 +23,7 @@ function getDevicePixelRatio() {
|
||||
1;
|
||||
return devicePixelRatio / backingStoreRatio;
|
||||
})();
|
||||
Util.releaseCanvas(canvas);
|
||||
return _pixelRatio;
|
||||
}
|
||||
|
||||
|
@ -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>;
|
||||
|
@ -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;
|
||||
}
|
||||
/**
|
||||
|
@ -957,4 +957,10 @@ export const Util = {
|
||||
return evt.changedTouches[0].identifier;
|
||||
}
|
||||
},
|
||||
releaseCanvas(...canvases: HTMLCanvasElement[]) {
|
||||
canvases.forEach(c => {
|
||||
c.width = 0;
|
||||
c.height = 0;
|
||||
})
|
||||
}
|
||||
};
|
||||
|
@ -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,
|
||||
|
@ -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>;
|
||||
|
Loading…
Reference in New Issue
Block a user