-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Memory leak caused by non disposed scene, when using routes #449
Comments
Thanks for raising this @fakedob I will take a look to it 🙏🏻 |
@fakedob can you confirm for me this is only happening with 3D models? If you use geometries with textures you get the same result? Just to narrow down I'm doing some tests currently |
Hey @alvarosabu sorry for delay, I wanted to be sure I test it properly before replying. I have loaded the test with the house and graves into a page for this test and went in and out using the router. The result is the same, basically, it loads the assets and does not dispose them upon leave, leading into 1.5mb left into memory. I have checked the commit in the pull request and understood, that you are trying to dispose some of the objects while traversing the main one. Have you looked into this thread and proposed solution? |
Hey @fakedob I just tried the solution they provided but I am having trouble measuring the before and after, looking at the total allocated size remains similar but then looking for specific classes inside they are removed when dispose of. How do you check if the geometries, materials, and textures have been properly disposed of and free out of memory? |
Investigating a little I saw this explanation @fakedob https://discourse.threejs.org/t/memory-usage-increases-upon-loading-model/58846/4
Make sure you’re not storing your meshes in any arrays, besides scene.children (I mean, you can and often need to, but you have to remember to remove the meshes from said arrays - otherwise they remain in memory forever.) Meshes stored in arrays that are used during the runtime will not be removed from memory until the mesh is removed from said array. |
Hi @yyx990803 thanks for offering your help. Just added you here for proper context When using Memory.diposal.v-if.mp4When navigating to a new route, Memory.disposal.vue-router.mp4My rough guess is that they continue being referenced on the custom renderer and that's why the garbage collector cannot free them but I'm not sure of this. No idea how to "dispose" the custom render. Here is a reproduction link https://stackblitz.com/edit/tresjs-basic-ejbcex?file=package.json,src%2Fmain.ts,src%2Fpages%2Findex.vue,src%2Fpages%2Fempty.vue,src%2Fstyle.css To debug maybe is gonna be easier to clone https://github.com/Tresjs/tres/tree/bugfix/449-memory-management and run the playground Thanks again 🙏🏻 |
Hey @fakedob so we still investigating, we did some improvements but the issue of memory allocation not being released on route change is still there and it doesn't seem trivial. I will get back to you as soon we have news. Sorry |
I think this method can be used to create a calling method inside the primitive and call it directly when the scene is destroyed. |
Thank you so much for your help guys, I will try this method and hope it will do the trick. Temporarily, as a workaround, I am loading a separate page into an iframe and control it via post messages. It is very limiting approach, but at least it doesnt crash the web app on mobile. I will let you know how does it behave when calling the cleanup method asap. |
Hello, I also encountered this problem. Is it solved now |
No, unfortunately, I didn't find an easy way around. The way I approached this problem finally, was to load the thres renderer into an iframe, which basically runs another window process, thus, when navigating away, the browser takes care of its memory. I know it looks a bit dirty, but it works. Just to give you another hint, I made a 2 way communication between the main and the child process to pass data of what needs to be loaded etc and control it as I would do with APIs. I hope this information help you, good luck. |
@alvarosabu Hello, I also encountered this problem. Is it solved now |
Is it a question? |
|
Describe the bug
In our project, we use a bit big bigger models and we test our app on mobile browsers. While observing the memory, it became clear that unmounting the TresCanvas, does not properly dispose the scene and some (maybe all) internal objects. So navigating in and out a few times on iOS device, cause the page to crash and reload, because it runs out of memory.
Unfortunately, my understanding of three.js is not much, but I had similar issues in the past and it was related to the way the scene and objects, that were added to the scene, being not properly disposed. Its possible that some references to some internal TresJS objects are also the cause of the issue. I just dont know.
Its also possible that I am missing something in the way I use the framework (which will be the best for me), so hopefully someone can give me a hand with this.
Thank you!
Reproduction
https://stackblitz.com/edit/tresjs-basic-tmk778
Steps to reproduce
To reproduce, open the reproduction link in a Chromium browser and use the
Memory
tab in the dev tools.At the top of the web page, you will find a basic navigation, that routes into two separate pages, where "The Experience" loads the TresCanvas and "Home" is used to unmount the other one.
System Info
No response
Used Package Manager
npm
Code of Conduct
The text was updated successfully, but these errors were encountered: