7

In this project I am working on I have several Collada models being displayed and then removed when not needed anymore. There seems to be a memory leak somewhere in the project and I am looking for ways to get it to run as smooth as possible as time is not on my side… I feel like I don't remove the meshes the right way and that this might cause some of the memory leakage I have.

I load the objects with LoadObject(level_1_character, "Assets/Level_1_Character.dae"); for example, where level_1_character is a Object3D. This calls the following function:

function LoadObject(name, url) {
            var mesh, geometry, material, animation;
            var loader = new THREE.ColladaLoader();
            loader.options.convertUpAxis = true;
            loader.load(url, function(col) {
                mesh = col;
                geometry = col.scene;
                name.name = url.toString();
                name.add(geometry);
            });
        }

I add the objects to the scene depending on the level through scene.add(level_1_character); and then remove it by doing the following:

level_1_character.traverse(function(child){
            if (child instanceof THREE.Mesh) {
                child.material.dispose();
                child.geometry.dispose();
            }
        });

I am not sure if this actually fully removes the object though. It seems as though the objects still are present in memory. Any idea what I'm doing wrong here?

Tim
  • 8,932
  • 4
  • 43
  • 64
fvltmn
  • 71
  • 3
  • I came across [this post](http://stackoverflow.com/questions/14650716/deallocating-object3d) which suggests to rather use `if (child.geometry !== undefined) {` instead of `if (child instanceof THREE.Mesh) {` as I do. When I do though, the commands get executed even after the geometry has been disposed beforehand. I check this by putting an `alert` function inside the if statement. I suppose this means the geometry still does not get disposed of correctly… – fvltmn Feb 26 '15 at 12:21
  • take a look at http://stackoverflow.com/questions/33152132 – gaitat Oct 19 '15 at 12:59

0 Answers0