Memory usage with animations

I have a problem with the memory usage of a scene while animating some meshes.
I have a mesh imported from blender that represents a moving crane. I receive several updates per seconds about the state of the crane : its position and the position of its attached tong.
So every time I receive a new position information, I clear the mesh’s animations, push a new one with its new destination and launch it with the following code:

this.mesh.animations = [];
this.mesh.animations.push(animation);
this.scene.beginAnimation(this.mesh, 0, 1000, false, 1,

My problem is that the engine seems to keep a lot of references to animation elements like RuntimeAnimation, Animatables, etc. as well as position vectors that are never cleaned. Over time, this crashes the browser.

Although if I stop the position updates (so I don’t create any new animations), the memory falls back to normal(-ish) after a while.

About the scene, I have a few hundred meshes. Most of them are cubes but I couldn’t make instances of them because they all have different properties. The crane and tong have about 5000 vertices each.
Also, almost all meshes have an attached label that is composed of a plane with a texture showing the name of the element.

Can anybody give me pointers about what’s going on and how I could fix this situation?
Thanks!

EDIT:
I tried to lower the duration of the animations so they would be quicker than the refresh rate of the crane and I noticed that the memory consumption seemed more stable (I’ll let it run for a few hours to be sure).
Could my problem be due to the fact that I am creating new animations before the previous ones are finished?

Hello it is complicated to help with no repro but maybe you would like to try calling scene.stopAllAnimations() before starting a new animation

Thanks, I’ll try to call stopAllAnimations tomorrow. I’ll see if I can set up a small repro also.

Could you explain what happens to unfinished animations when new ones are added for the same mesh? Are they completed right away or do new animations take over and prevent them from completing until they are finished?

They are supposed to be stopped if you call beginAnimation
But I would love to confirm we have no leak if you can have a small repro in the PG

I tried to replicate the problem in a PG but without success: the memory consumption remains very stable (Good for BJS! :slight_smile: )

This helped me notice that in one of the mesh animations, I was calling animations.push() without clearing the animations array first. This definitely explains a memory pile up although not why lowering the animation duration had such an effect.
I’ll keep investigating.

I tried to call stopAllAnimations before calling a new one but it didn’t change anything by the way. This makes sense if finished animations are cleared when done…

Yeah I bet you may have a leak somewhere with these arrays :slight_smile: Keep us posted!

Ok, after spending some time going through the code base hunting for non disposed meshes and non reset animation arrays, I managed to have a stable memory consumption. So it was indeed all on our side! :slight_smile:

Thanks!

2 Likes