dungtm Posted June 3, 2016 Share Posted June 3, 2016 I have a page that loads about 40K meshes with BabylonJS (run in Chrome). When I disposed the scene (by using scene.dispose()), and deleted all the Javascript references to the meshes, the Javascript memory for the tab was reduced (not very fast, however), but the total memory occupied by the tab did not change (see the picture attached). The next time when I tried to recreate the scene, the memory increased rapidly and the page crashed. Can anyone explain me what contributes to the total memory in Chrome (apart from Javascript memory) and why it was unchanged? Another question is why the GPU memory persists (in the Chrome tab process and GPU process), even when I dispose the scene and hide the canvas? (It reduced significantly when I closed the Chrome tab). Is there anyway to release GPU memory when the 3D graphics is no longer used? Thanks in advance for your help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 3, 2016 Share Posted June 3, 2016 Hey! Chrome is known for his catastrophic memory management can you try engine.dispose()? and also try to remove canvas from the DOM Quote Link to comment Share on other sites More sharing options...
ferat Posted June 8, 2016 Share Posted June 8, 2016 I have a similar problem with my app (using NW.js to run in Desktop Mode) . When i click a button, I call the code below: resetScene: function(meshName) { scene.dispose(); return this.createNewScene(meshName); //Creates a new scene } The scene.dispose() works well, but the memory is not released. And I have the same problem with material.dispose(), always that i call it, the memory is not released. When I create a new material, the memory increases. What can i do to solve this? Thanks a lot Quote Link to comment Share on other sites More sharing options...
dungtm Posted June 9, 2016 Author Share Posted June 9, 2016 Hey, First of all, thank you Deltakosh for your response and your time. After many tests, I found that the problems are related to the references that are not removed after the dispose() method. If you happen to have a reference to scene, or camera, or only one mesh somewhere, a lot of memory will not be released. @ferat: you should scan all your code and make sure that there is no reference to any object in the scene (including the camera and the scene itself). For example, the scene reference should be deleted by scene = null. This is (partly?) due to the fact that object scene is still big after calling dispose(). I scanned the code and found that, for example, the _activeMeshes in scene are not cleared in dispose(). This array holds references to all active meshes. The camera also has an array _activeMeshes which hold the same references. Any mesh in the scene has reference to the scene. This means if you have one reference to only one mesh, this will consequently keeps the scene in memory, even when you deleted the scene by scene = null. This is quite tricky and non obvious because when we dispose a mesh or a scene, we expect that its memory related to the 3D graphics be released, even when we mistakenly, or intentionally, keep a reference. I would propose some improvements to avoid unwanted memory leaks: 1) Clear all _activeMeshes at scene.dispose(); 2) Remove the reference to the scene in Node.dispose (or Mesh.dispose). 3) In general, in the dispose() of an object, clear all the references it keeps to the external objects, .... In addition, the more we remove references, the easier and more rapid the job of the garbage collector. Pls correct me if I am wrong. Again, thanks for your help. Quote Link to comment Share on other sites More sharing options...
ferat Posted June 9, 2016 Share Posted June 9, 2016 Thanks @dungtm. I will scan my code for references. Thanks a lot for your help!! Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 9, 2016 Share Posted June 9, 2016 @dungtm - great post. I have found that GC management is poor in Chrome, however, there appears to be unknown issues with BJS scenes in most browsers. But this is a young framework comparatively, and posts such as this help the "team" building this to optimize in every release. I've taken a hard look (as much as my experience allows) at GC in Chrome, and can hardly distinguish what is handled in minor GC and major GC, although most of the latency and memory issues appear to be with major GC such as disposing of items such as textures and meshes. DB Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.