kurhlaa Posted February 18, 2018 Share Posted February 18, 2018 Hi, On a Stackoverflow found an advice to set the mesh variable to null after the dispose call (to tell the GC he can collect). Something like: ball.dispose(); ball = null; ... is this needed nowadays or is already implemented in BJS ? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 18, 2018 Share Posted February 18, 2018 It's not BJS specific, but JavaScript and is needed. As long as there is something in memory pointing at your object then it cannot be released from memory. If you are creating a lot of objects and not cleaning up then you will get a large memory footprint or memory leak. The Garbage Collector can't collect objects that have references - it can only collect "garbage" or unreachable objects. So, if your ball variable is a reference that leaves scope then it is also cleaned up, so you don't need to set to null. Good practice to set variables to null and avoid global references. edit: A disposed mesh it is removed from the scene, so I think you just need to make sure you don't have any references in your own code. BabylonJS takes care of references in framework for you: https://github.com/BabylonJS/Babylon.js/blob/7112a6542efc8aeb26c8b7b6568c61535716c01a/src/Mesh/babylon.abstractMesh.ts#L1424 NOTE: dispose() has two (for AbstractMesh) optional parameters: doNotRecurse?: boolean, disposeMaterialAndTextures: boolean = false So, you can be more specific when disposing with your intentions. GameMonetize and kurhlaa 2 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.