|
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
(comments are locked)
|
|
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. Hello Rune, i dont think there is a way to differentiate between hiding and actual deletion. as both of the call OnDisable. For now i delete the mesh in OnDisable and create it again in OnEnable. I still dont understand why it requires manual deletion when everything else is garbage collected. Its is inconsistency am concerned about.
Jan 13 '10 at 05:33 AM
pkamat
I added to my answer above to explain this.
Jan 13 '10 at 03:53 PM
runevision ♦♦
Thank you so much for this! Completely fixed my problem! Thank you again!
Oct 11 '11 at 03:59 PM
HarvesteR
(comments are locked)
|


humm image link is missing.. http://img687.yfrog.com/i/meshleak.jpg/