vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
2.03k stars 301 forks source link

[Feature request] Globe() manually release #15

Closed lslzl3000 closed 4 years ago

lslzl3000 commented 4 years ago

Is your feature request related to a problem? Please describe. In many cases, we need to free all memory / three.js objects without refresh browser. e.g. one-page app or dev with hot-reload in webpack,... But I can't find any way to release them in current version. Recall Globe() would create new scene but the old one seems remain in the memory, and the scene would be slow rendering.

Describe the solution you'd like There could be an API, e.g myGlobe.destroy()/.free()/..., to release all canvas/dom/threejs objects in old scene.

vasturiano commented 4 years ago

@lslzl3000 for this purpose you can invoke the internal method ._destructor() but it's merely a shortcut method that pauses the animation and empties all the layers, which you can do yourself directly. https://github.com/vasturiano/globe.gl/blob/6dfbd2824e95dac2cb9af8664a8e37301871c381/src/globe.js#L231-L241

lslzl3000 commented 4 years ago

@vasturiano Ok, that's a way to start. What about the canvas/doms/Globe instance/threejs objs? I think we need to consider more to avoid memory leak

vasturiano commented 4 years ago

The three objects will be recycled as you empty the data layers. The DOM node is owned by the application so it's not up to the component to clean. The Globe instance will be garbage collected when unreferenced from your code.

lslzl3000 commented 4 years ago

Thanks for reply, I will test _destructor() in my scenes. It seems work for me.

chientrm commented 2 years ago

_destructor work for me, too. Very nice!