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

Free memory when a-scene is unmounted #110

Open
ebhoren opened this issue Oct 8, 2017 · 2 comments
Open

Free memory when a-scene is unmounted #110

ebhoren opened this issue Oct 8, 2017 · 2 comments

Comments

@ebhoren
Copy link

ebhoren commented Oct 8, 2017

I’m using AFRAME with react-aframe and i need to unmount scene at a certain time. Is there a way to free memory used by AFRAME after the scene as been unmounted?

Thanks

@glidepro
Copy link

glidepro commented Jun 3, 2018

@ebhoren probably way too late, but I was having a similar issue to you.

I am rendering 2 scenes, each displayed in a React Tab. I was able to switch between the scenes in the tabs without any apparent visual issue, but noticed that each time I switched to display/re-display the scene, a new WebGL context was created.

On the version of Chrome I'm using, after 16 contexts are created, Chrome warns you in the console that it's going to start dropping the oldest context when a new one is created. I also noticed that leaving the scene open in a tab for a long time eventually caused the browser to become slugglish.

The following code appears to clear these issues:

AFRAME.registerComponent('deallocate', {
  remove: function () {
    THREE.Cache.clear();
    this.el.renderer.forceContextLoss();
  },
});

and added it as an attribute to the Scene thus:
<Scene deallocate>

While it doesn't tie into React's lifecycle events, as the Scene component is removed from the DOM, it triggers the A-Frame component's remove function and the clean-up happens there.

(Caveated by the fact that I'm not an expert with WebGL, Three or A-Frame)

@ebhoren
Copy link
Author

ebhoren commented Jun 4, 2018

@glidepro Yes, it's a bit too late but i really appreciate your solution.
Thanks for sharing it to the world 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants