Each time i delete the game object, its mesh seem to be still existing. Is there something explicitly i have to do to delete the mesh?
I tried delete the mesh in OnDisable() using DestroyImmediate but the side effect is the mesh gets deleted if i hide the gameobject.
Am creating a mesh from scratch like this:
The image shows the before and after screen shots
asked Jan 11 '10 at 09:15 PM
Currently the best you can do is to delete the mesh in OnDisable() like you mentioned yourself.
If you want to avoid deleting the mesh when hiding the GameObject, you can delete the mesh in your own function (say, MyDestroy), and manually call that function when you know you are about to destroy the GameObject for real (not just hiding it).
The mesh is not garbage collected because the engine still keeps a reference to it. You can find the meshes you have created by using FindObjectsOfType(), even if no GameObject currently keeps a reference to it. This is also why it is shown in the editor.
If you want to make Unity garbage collect objects that are not currently used, you can use Resources.UnloadUnusedAssets() - this is also called by Unity whenever you load a new scene. However, in your case it is definitely better to destroy the mesh yourself since you know it is not needed by other objects.