feat: cleanup resources

This commit is contained in:
amhsirak
2025-03-04 22:40:39 +05:30
parent bad60077d4
commit bcff0e5d83

View File

@@ -218,4 +218,24 @@ export class CanvasRenderer {
}
}
/**
* Clean up resources
*/
public dispose(): void {
// Cancel any pending frame requests
if (this.lastFrameRequest !== null) {
cancelAnimationFrame(this.lastFrameRequest);
this.lastFrameRequest = null;
}
// Clear the image cache
this.imageCache.clear();
// Clear canvases
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
if (this.offscreenCtx && this.offscreenCanvas) {
this.offscreenCtx.clearRect(0, 0, this.offscreenCanvas.width, this.offscreenCanvas.height);
}
}
}