Skip to content

Commit 4dcd3d4

Browse files
committed
fix(lru): collect all the nodes to remove and then remove them in one go
1 parent 2480cf0 commit 4dcd3d4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/utils/lru.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ export class LRU {
141141
}
142142

143143
disposeDescendants(node: Node): void {
144+
// Collect all the nodes which are to be disposed and removed.
145+
const nodesToDispose: Node[] = [];
144146
node.traverse(n => {
145147
if (n.loaded) {
146-
n.dispose();
147-
this.remove(n);
148+
nodesToDispose.push(n);
148149
}
149150
});
151+
152+
// Dispose of all the nodes in one go.
153+
for (const n of nodesToDispose) {
154+
n.dispose();
155+
this.remove(n);
156+
}
150157
}
151158
}

0 commit comments

Comments
 (0)