Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data structures are not garbage collected on dispose #15972

Closed
revyTH opened this Issue Mar 14, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@revyTH
Copy link

revyTH commented Mar 14, 2019

Description of the problem

see https://discourse.threejs.org/t/dispose-things-correctly-in-three-js/6534

I am experiencing problems on correctly disposing a scene and all the associated data structures.

In my test I followed these steps (using Chrome devtools):

  1. Start from an empty scene, force garbage collection and taking memory snapshot.
  2. Adding meshes to the scene with the "ADD MESHES" button (100 meshes added per click), force garbage colelction and take memory snapshot.
  3. Dispose scene using the "DISPOSE" button, wait some seconds, force garbage collection and taking memory snapshot.
RESULT (comparison between snapshot 3 and snapshot 1):

snapshots_3_1

As you can see most of the three.js data structures are kept in memory and not garbage collected.

EXPECTED BEHAVIOUR

All the three.js data structures should be garbage collected, giving a memory state comparable to the initial state.

This is the live plunker:

https://plnkr.co/edit/pmeB0t3tEbOAaKdebhbr

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

@mrdoob mrdoob changed the title Three.js data structures are not garbage collected on dispose Data structures are not garbage collected on dispose Mar 15, 2019

@mrdoob

This comment has been minimized.

Copy link
Owner

mrdoob commented Mar 15, 2019

dispose() methods deallocates memory from the GPU (and not from the CPU).

@Mugen87

This comment has been minimized.

Copy link
Collaborator

Mugen87 commented Mar 15, 2019

The main issue was that the test program of the OP had multiple console.log statements. When objects are logged to the console, they are not GC collected even if a program has no references to it anymore (which is very confusing^^). We had once a similar issue right here: #11378

Removing the console.log statements resolved the issue, see https://discourse.threejs.org/t/dispose-things-correctly-in-three-js/6534/14?u=mugen87

@Mugen87 Mugen87 closed this Mar 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.