Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
Three.JS instance can't be re-created

I'm trying to destroy (or destruct or dispose) an 'instance' of Three.JS using this:

Full example: https://jsfiddle.net/v7oLzs4m/58/

function kill() {
  const rendererDomWas = renderer.domElement;
  renderer.dispose();
  controls.dispose();
  renderer = scene = camera = controls = null;
  document.body.removeChild( rendererDomWas );
  shouldRender = false;
}

function animate() {
  if(!shouldRender) {return} // no more requesting animation frames if 'shouldRender' is false
  frameID = window.requestAnimationFrame( animate );
  renderer.render( scene, camera );
}

(i.e. disposing, setting references to null, and stopping the draw loop from touching renderer while shouldRender is false)

It appears to work at first (The renderer content stops showing) but when I re-create the instance, it never comes back.

It's as if something is still... holding onto the GLContext which prevents it from being invoked again.

Why can't I re-create a new instance of Three.JS?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm not sure why this works (since I was already doing this in my Fiddle...)

But it turns out the secret ingredient (for me) to letting Three.JS get GC'd/disposed is this:

window.cancelAnimationFrame(frameID);

I suppose that this stops the render function from being stored in the hardware-level draw loop, which holds references to GLContext (and the chain)

The GC can't ever happen unless the 'loop is broken'

(Correct me if I'm wrong please)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda