andriy
andriy

Reputation: 155

Correctly disposing of curves in THREE.JS

I have a sphere with multiple moving points on it, and I am drawing curves connecting the points like this:

Curves

Since the points are moving, I draw these curves for every frame, and thus there is a lot of memory overhead that I am worried about.

Each curve is drawn with

// points = array of Three.Vector3 size 40
path = new THREE.CatmullRomCurve3(points)
mesh = new THREE.Mesh( 
                      new THREE.TubeGeometry(path,64,0.5,false), // geometry
                      new THREE.MeshBasicMaterial({color: 0x0000ff}) // material
                     ) 
scene.add(mesh)

and for disposal:

scene.remove(mesh)
mesh.material.dispose()
mesh.geometry.dispose()

It does not let me, however, dispose of my array of 40 Three.js vectors points and of my CatmullRomCurve3 path.

What is the issue, and how do I dispose of the new THREE.Vector3() and new THREE.CatmullRomCurve3().

Upvotes: 1

Views: 360

Answers (1)

Mugen87
Mugen87

Reputation: 31036

What is the issue, and how do I dispose of the new THREE.Vector3() and new THREE.CatmullRomCurve3().

dispose() methods in three.js are mainly intended to free GPU memory which is associated with JS objects like geometries, materials, textures or render targets. Instantiating curves and plain math entities like Vector3 do not cause an allocation of GPU memory.

Hence, it should be sufficient to just remove any references to path so it can be cleaned up by the GC.

Upvotes: 3

Related Questions