feat: cleanup memory

This commit is contained in:
amhsirak
2025-03-04 22:40:03 +05:30
parent 34057f9b13
commit 2d638a6239

View File

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