Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLMorphtargets: Dispose morph textures when corresponding geometry is disposed. #23104

Merged
merged 1 commit into from
Dec 29, 2021

Conversation

0b5vr
Copy link
Collaborator

@0b5vr 0b5vr commented Dec 28, 2021

Original discussion: https://discourse.threejs.org/t/how-do-i-free-morph-textures/33033

Description

Morph textures are not disposed when disposing corresponding geometries.

In WebGLMorphtargets, since each morph textures are one-to-one to each geometries and it only referred from this part,
it can be safely disposed once geometry is disposed.

I have added an event listener of 'dispose' to geometry that disposes the morph texture.
This will ensure morph textures be freed once it's no longer necessary.

@0b5vr
Copy link
Collaborator Author

0b5vr commented Dec 28, 2021

I've built the three.js with this patch and made a demo on glitch: https://glitch.com/edit/#!/three-r133-vtf-morph-memory-leak

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2021

To clarify, morph textures are maintained in a weak map. So if there are no references to the geometry, the texture should automatically disappear. However, like mentioned at the forum this solution is more consistent compared to other parts of the code base.

@Mugen87 Mugen87 changed the title Dispose morph textures when corresponding geometry is disposed WebGLMorphtargets: Dispose morph textures when corresponding geometry is disposed. Dec 28, 2021
@Mugen87 Mugen87 added this to the r137 milestone Dec 28, 2021
@mrdoob mrdoob merged commit 74437e6 into mrdoob:dev Dec 29, 2021
@mrdoob
Copy link
Owner

mrdoob commented Dec 29, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants