Skip to content

Commit 7618da3

Browse files
authored
Update IfcManager.ts close()
Update IfcManager.ts close: Update `close()`, to avoid memory leaking, by disposing geometry and material of IFCModel on closing.
1 parent cc47d56 commit 7618da3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

web-ifc-three/src/IFC/components/IFCManager.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,19 @@ export class IFCManager {
197197
* @scene Scene where the model is (if it's located in a scene).
198198
*/
199199
close(modelID: number, scene?: Scene) {
200-
this.state.api.CloseModel(modelID);
201-
if (scene) scene.remove(this.state.models[modelID].mesh);
202-
delete this.state.models[modelID];
200+
try {
201+
this.state.api.CloseModel(modelID);
202+
const mesh = this.state.models[modelID].mesh;
203+
const { geometry, material } = mesh;
204+
if (scene) scene.remove(mesh);
205+
geometry?.dispose();
206+
geometry = null;
207+
Array.isArray(material) ? material.forEach(m => m.dispose()) : material?.dispose();
208+
material = null;
209+
delete this.state.models[modelID];
210+
} catch(e) {
211+
console.warn(`Close IFCModel ${modelID} failed`);
212+
}
203213
}
204214

205215
/**

0 commit comments

Comments
 (0)