I've been working on a project that utilizes webGl and Three.js. The main issue I'm facing is related to memory deallocation.
As the game progresses, a large number of objects are created, leading to excessive memory allocation. Despite trying various approaches in my code, nothing seems to be effective.
Currently, I am using the following function:
function deallocatingScene(){
for (var i = scene.children.length - 1; i >= 0 ; i--) {
deallocateObject(scene.children[i]);
}
}
function deallocateObject(obj){
scene.remove(obj);
if (obj.geometry) {
obj.geometry.dispose();
}
if (obj.dispose) {
obj.dispose();
}
}
Any suggestions on how to improve this implementation?