Rasheduzzaman Sourov Rasheduzzaman Sourov - 3 months ago 45
Javascript Question

Is there any way to delete a buffer in threejs to reduce GPU memory leak?

I have a very big mesh with more than 5 million triangles. I have used

BufferGeometry
with
position
,
color
,
normal
and
index
attribute. At some point, i have to remove some
indices
from the
index
attribute.

Now, i have seen that, there is no way to remove elements from the current
index
buffer. I have to create a new
BufferAttribute
and set it as
index
buffer of the geometry. But i haven't found a way to delete the previous
index
buffer which has been uploaded to GPU already. This is creating a GPU memory leak for me. I don't want to dispose the previous geometry and create a new one.

My question is - is there any way to delete the previous
index
buffer without disposing the
BufferGeometry
.

Answer

You can dispose of a buffer by doing:

BufferGeometry.dispose()

This will remove the object from the GPU

EDIT:

So if you read the onGeometryDispose you can come up with that answer, simply delete the attribute by calling what i suspect as a private js function but you still have access to it

Code Example:

if ( buffergeometry.index !== null ) {
    deleteAttribute( buffergeometry.index );

}

Source for answer: https://github.com/mrdoob/three.js/blob/dev/src/renderers/webgl/WebGLGeometries.js#L52-L56

Final Resolution:

Make sure to set the update flags.

http://github.com/mrdoob/three.js/wiki/Updates

Comments