From 9da7ddf2f79f99d9b18c6804a4cf1f723a0aaac0 Mon Sep 17 00:00:00 2001 From: Davor Hrg Date: Sat, 14 Sep 2024 19:49:22 +0200 Subject: [PATCH] fix mem leak from groups array --- packages/render-threejs/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/render-threejs/index.js b/packages/render-threejs/index.js index add012e..06553e9 100644 --- a/packages/render-threejs/index.js +++ b/packages/render-threejs/index.js @@ -31,7 +31,7 @@ export function RenderThreejs({ let renderTimer let meshColor = new Color(1, 1, 1) - const entities = [] + let entities = [] const groups = [] let canvas @@ -202,10 +202,12 @@ export function RenderThreejs({ groups.forEach(group => { _scene.remove(group) }) - entities.forEach(ent => { - if (ent.geometry) ent.geometry.dispose() - }) - entities.length = 0 + let old = entities + entities = [] + groups.length = 0 + setTimeout(()=>{ + old.forEach(ent => ent.geometry?.dispose?.()) + },0) scene.items.forEach(item => { const group = new Group() groups.push(group)