From 2d638a623931e6dc69ade2dbff94c227f8c8e575 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 4 Mar 2025 22:40:03 +0530 Subject: [PATCH] feat: cleanup memory --- src/components/recorder/Renderer.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/recorder/Renderer.tsx b/src/components/recorder/Renderer.tsx index 212a60dc..1d778d5b 100644 --- a/src/components/recorder/Renderer.tsx +++ b/src/components/recorder/Renderer.tsx @@ -174,5 +174,28 @@ export class CanvasRenderer { } } + /** + * Cleans up resources to reduce memory usage + */ + private cleanupMemory(): void { + // Limit image cache size + if (this.imageCache.size > 20) { + // Keep only the most recent 10 images + const keysToDelete = Array.from(this.imageCache.keys()).slice(0, this.imageCache.size - 10); + keysToDelete.forEach(key => { + this.imageCache.delete(key); + }); + } + + // Suggest garbage collection + if (window.gc) { + try { + window.gc(); + } catch (e) { + // GC not available, ignore + } + } + } + } \ No newline at end of file