Three.js: Clear scene but memory is not removed.

Created on 19 Aug 2017  路  9Comments  路  Source: mrdoob/three.js

I updated to r87 recently, in r86 I dispose and remove all from the scene after clear garbage memory is clear but in r87 is not.

I check in memory debug on firefox browser found it remain in renderItems at src/renderers/webgl/WebGLRenderLists.js and so I add code renderer.dispose() memory is cleared, but I not want to destroy the renderer.

Three.js version
  • [ ] Dev
  • [x] r87
  • [ ] ...
Browser
  • [ ] All of them
  • [ ] Chrome
  • [x] Firefox
  • [ ] Internet Explorer
OS
  • [ ] All of them
  • [ ] Windows
  • [ ] macOS
  • [x] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)

Most helpful comment

Have you tried

renderer.renderLists.dispose();

Which removes all the renderers references to renderItems?

( I hit this problem which is why renderLists is now exposed, although this was before r86)

All 9 comments

Can you demonstrate the issue with a simple, live example?

Ok, I write sample here:

http://jsfiddle.net/akmcv7Lh/177/

Have you tried

renderer.renderLists.dispose();

Which removes all the renderers references to renderItems?

( I hit this problem which is why renderLists is now exposed, although this was before r86)

Yes, renderer.renderLists.dispose(); is will remove memory,

But should I use this?, because document says: renderLists used internally.

Per my investigation, the cause is that the removed items don't get cleared timely in 'renderItems'. I've made an attempting PR to fix it.
https://github.com/mrdoob/three.js/pull/11996

It's OK to use renderLists.dispose() , I exposed it for this purpose. It doesn't destroy any state that can't be reestablished from your scene(s) and camera object(s) as required. see #11497

I am okay with renderLists.dispose(). Meanwhile I also think It's a good practice to release any unused object as soon as possible. So my PR still makes sense.

@jchen10 As I said, RenderLists act as caches of RenderItems. RenderList.init() is called for each render list every frame, that is 60 times a second. With your PR, new RenderItems are allocated each frame and old RenderItems discarded, this creates heap pressure and more frequent garbage collections resulting in less smooth animation/rendering. You will see this in browser profiles, especially for scenes with large number of objects. This is why init() doesn't zero the internal array.

@aardgoose Thanks much for your clarification.

Was this page helpful?
0 / 5 - 0 ratings