mrdoob/three.js — Issue #1162: Textures not unloaded when mesh is removed
Author: rhuitl
Created: 2012-01-21 22:39:05+00:00
State: open

I noticed that textures stay in memory (according to WebGL Inspector) even after the last mesh using them has been removed. I add meshes like this:

```
zmesh = new THREE.Mesh( geom[geometry_no], new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture( tex_fn, {}, function() { render(); }),
}));

zmesh.position.set( pos[0], pos[1], pos[2] );
zmesh.quaternion = new THREE.Quaternion(ori[1], ori[2], ori[3], ori[0]);
zmesh.useQuaternion = true;
zmesh.updateMatrix();
zmesh.overdraw = false;
scene.add( zmesh );
```

and delete them like this:

```
for(var i = 0; i < scene.objects.length; ++i) {
if(scene.objects[i] instanceof THREE.Mesh) {
scene.remove(scene.objects[i]);
i--;
}
}
```

Do I have to delete the textures manually? I'm not aware of any other references to the texture except for "map" in zmesh.