Closed realtomaszkula closed 2 years ago
@zetsnotdead thanks for finding this mem leak case and for your detailed report. Much appreciated.
It should be fixed in the new version of the lib. Please try it out. The cause was that the sphere geometries weren't being properly disposed of before replacing with new ones.
Your suggestion of scaling the sphere is interesting (in fact that's how that layer was initially developed). The issue with it is that you want the tiles to grow sideways on the surface of the globe. While if you scale the sphere object they will rise up from the center of the globe and only become visible in it its final state, while animating the entering objects. That's why it's required to create a new sphere object each time, to achieve the intended visual effect.
That was quick 😮 I can confirm it works 🎉 Great work! 😍 Thanks a lot.
To Reproduce Update the
Globe.tilesData()
in asetInterval()
. After some time it will crash the browser because of the lack of memory.I've created a simple repo to showcase the issue: https://stackblitz.com/edit/web-platform-85n1dt
It does nothing special, just extends the default demo of the tiles layer with the folowing code:
If you open up the developer tools, in the memory tab, you will see that the memory usage will keep growing until it crashed the browser.
Expected behavior It should not crash the browser because of the lack of memory.
Desktop:
The issue is caused by creating a THREE.SphereBufferGeometry object in an animation callback function. https://github.com/vasturiano/three-globe/blob/638f4fa3ae3003e74ca57b157208cc319242dcf9/src/layers/tiles.js#L81-L95 If you comment out the lines 81-89 the memory usage is constant, but the animation stops working (duh).
Ideally the object would be created once, outside of the animation callback, and then only updated in the animation callback. But I'm too big of a Threejs noob to help out here.
I did manage to make it work in my app, by making the following workaround:
The diff generated by patch-package looks like this: