ThatOpen / web-ifc-three

The official IFC Loader for Three.js.
https://ifcjs.github.io/info/
MIT License
506 stars 132 forks source link

Bug memory leak in ifcmanager.close() #145

Closed D4ve-R closed 1 year ago

D4ve-R commented 1 year ago

The current implementation of IFCManager.close in IFCManager.ts leaks memory, because IFCModel is not disposed properly in a threejs-way.

/**
     * Closes the specified model and deletes it from the [scene](https://threejs.org/docs/#api/en/scenes/Scene).
     * @modelID ID of the IFC model.
     * @scene Scene where the model is (if it's located in a scene).
     */
    close(modelID: number, scene?: Scene) {
        this.state.api.CloseModel(modelID);
        if (scene) scene.remove(this.state.models[modelID].mesh);

       // this.state.models[modelID].mesh.geometry.dispose() & this.state.models[modelID].mesh.material.dispose()
       // should be called here, before deleting reference

        delete this.state.models[modelID];
    }