Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!