- Home /
VRam keeps climbing until Unity editor crashes.
The editor's statistics read "VRAM Usage: 8 mb of x mb (of unknown)" and that x number keeps climbing all the way to 1.34 gb where it crashes the entire editor. I'm assuming for some reason the game is exhausting video memory but I can't see why.
My game generates meshes from voxel data then destroys and recreates the mesh when it needs to be regenerated.
The meshes get destroyed by calling Destroy() on their gameobjects. What could be causing this apparent memory leak?
Answer by Bunny83 · Nov 16, 2014 at 07:26 PM
Do you actually destroy the mesh? i guess not. You also should use the sharedXXX properties in most cases. If you create a distinct mesh manually, assign it to .sharedMesh instead of .mesh as mesh will duplicate the mesh. A Mesh instance could be shared between multiple objects, so you should destroy it with Destroy when done.
Just to make that clear: $$anonymous$$eshes are managed objects by the Unity engine. Like all objects derived from UnityEngine.Object they aren't destroyed when you get rid of all references since they are managed. They can still be found with FindObjectsOfType. You have to destroy the $$anonymous$$esh objects manually. Each $$anonymous$$esh object represents a VBO (vertex buffer object). This count should also increase in your stats because everytime you create a new $$anonymous$$esh, a new VBO is created.
So either destroy them completely, or use a chunk-pool where you reuse the whole chunk (including GameObject and mesh).
I was using shared$$anonymous$$esh and it turns out that you have to destroy the $$anonymous$$esh object directly. It's not enough just to destroy the game objects that reference it. Thanks.