We are trying to create a single page app in which user can switch between multiple Three.js apps. However we are noticing constant increase in memory usage by the tab. Their is no memory leakage in our app and seems Three.js variables are not getting cleared from RAM.
Steps to recreate
I have noticed 2 bugs filed on chromium and firefox about this memory issue but no solution has been provided yet.
Please help me on how to release memory, most of stuff I found on internet are not helping.
PS: I have filed a bug at Three.js as well https://github.com/mrdoob/three.js/issues/4276
A memory leak in JavaScript is defined as an increase in application memory consumption over time because allocated objects are not released. In “old” languages like C and C++ the developer had to allocate and release the memory explicitly.
Memory leaks are a problem every developer has to face eventually. Even when working with memory-managed languages there are cases where memory can be leaked. Leaks are the cause of whole class of problems: slowdowns, crashes, high latency, and even problems with other applications.
Open the example in Chrome, open the Dev Tools, go to timeline, select memory and click the record button. Then go to the page and click The Button to start leaking memory. After a while stop the recording and take a look at the results:
The key in this case lies in the fact that after each drop in memory use, the size of the heap remains bigger than in the previous drop. In other words, although the garbage collector is succeeding in collecting a lot of memory, some of it is periodically being leaked. We are now certain we have a leak. Let's find it.
Here is what did the trick for me
This way, I was able to free more than 600MB of memory post moving to another page.
Update Answer by Mr. Doob and WestLangley Memory leak with three.js and many shapes
In webGLRenderer, after removing a mesh with
scene.remove( mesh )
,
you can deallocate the memory with
renderer.deallocateObject( mesh );
You can deallocate textures with
renderer.deallocateTexture( texture );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With