Jump to content

Disposing a mesh


kurhlaa
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...