Skip to content

Commit

Permalink
Merge pull request #987 from ThatOpen/memleak
Browse files Browse the repository at this point in the history
Fix Memory Leak
  • Loading branch information
beachtom authored Aug 11, 2024
2 parents 6761576 + b92d1ad commit da75e0c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<div id= "3dcontainer" style="width:100%; height: 90%;" ></div>
<input type="button" id="runcode" value="Run Code"/>
<input type="file" id="finput">
<input type="button" id="cmem" value="Clear Memory"/>
<input type="button" id="rcode" value="Reset Editor"/>
Log Level: <select id="logLevel">
<option value="6">Off</option>
Expand Down
4 changes: 4 additions & 0 deletions examples/viewer/web-ifc-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function Init3DView() {
AnimationLoop();
}

export function ClearScene() {
while(scene.children.length > 0) scene.remove(scene.children[0]);
}

export function InitBasicScene()
{
const directionalLight1 = new THREE.DirectionalLight(0xffeeff, 0.8);
Expand Down
12 changes: 10 additions & 2 deletions examples/viewer/web-ifc-viewer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IfcApplication } from './../../src/ifc-schema';
import { IfcAPI, LogLevel,ms, Schemas, IFCUNITASSIGNMENT, IFCAXIS2PLACEMENT3D,IFCLENGTHMEASURE,IFCCARTESIANPOINT,IFCAXIS2PLACEMENT2D,IFCCIRCLEPROFILEDEF,IFCDIRECTION,IFCREAL,IFCPOSITIVELENGTHMEASURE,IFCCOLUMN,IFCEXTRUDEDAREASOLID,IFCGLOBALLYUNIQUEID,IFCLABEL,IFCIDENTIFIER } from '../../dist/web-ifc-api';
import { IfcThree } from './web-ifc-three';
import { Init3DView, InitBasicScene, scene } from './web-ifc-scene';
import { Init3DView, InitBasicScene, ClearScene, scene } from './web-ifc-scene';
import * as Monaco from 'monaco-editor';
import * as ts_decl from "./ts_src";
import * as ts from "typescript";
Expand Down Expand Up @@ -81,7 +81,9 @@ window.InitWebIfcViewer = async (monacoEditor: Monaco.editor.IStandaloneCodeEdit
codereset.addEventListener('click', resetCode);
const coderun = document.getElementById('runcode');
coderun.addEventListener('click', runCode);
const changeLogLevelSelect = document.getElementById('logLevel');
const clearmem = document.getElementById('cmem');
clearmem.addEventListener('click', clearMem);
const changeLogLevelSelect = document.getElementById('logLevel');
changeLogLevelSelect.addEventListener('change', changeLogLevel);
Init3DView();
};
Expand Down Expand Up @@ -125,6 +127,12 @@ async function resetCode() {
location.reload();
}

async function clearMem() {
ClearScene();
ifcAPI.Dispose();
await ifcAPI.Init();
}

async function fileInputChanged() {
let fileInput = <HTMLInputElement>document.getElementById('finput');
if (fileInput.files.length == 0) return console.log('No files selected!');
Expand Down
3 changes: 2 additions & 1 deletion src/ts/web-ifc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,12 @@ export class IfcAPI {
}

/**
* Closes all models and frees all related memory
* Closes all models and frees all related memory. Please note that after calling this you must call Init() again to ensure web-ifc is in a working state.
*/
Dispose() {
this.ifcGuidMap.clear()
this.wasmModule.CloseAllModels();
this.wasmModule = undefined;
}

/**
Expand Down

0 comments on commit da75e0c

Please sign in to comment.