Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda