- Home /
Memory management tips
Looking into memory management in Unity, is below understanding correct?
Unity (mono runtime) managed mono objects and automatically release unused object during GC. This included object created on stack, script component,material and shader object.
Unity keep tracking of loaded texture and mesh objects. If no more reference on them, they can be released via Resources.UnloadUnusedAssets(). It's a good idea to call this when you load / unload lots objects with different mesh / texture or switching scene.
If you ever created new mesh / texture yourself. i.e. combined meshes, render to texture, you need manually destroy those objects your own when no longer used.
Regularly (manually) call GC won't benefits too much, but depends on your specific cases.
Use compressed texture if possible, they're load and rendered faster.
If you have more tips/tricky about memory management in Unity, feel free to share with us.
Thanks Favo. There's also a thread at http://answers.unity3d.com/questions/184680/memory-leak-gallore.html that references this one.
"Regularly (manually) call GC won't benefits too much, but depends on your specific cases."
In a specific case I´ve faced a while ago it not only benefited but also prevented the allocated heap of increasing over time.
CJ, can you elaborate a bit? Definitely curious about your experiences.
I made a few comments here: http://answers.unity3d.com/questions/183999/unity-ios-controlling-heap-size-growth.html
System.GC.Collect(); manually called after destroying objects resolved memory crashs for us
Your answer
Follow this Question
Related Questions
know how many free memory on System? Windows Standalone 1 Answer
AudioClip.preloadAudioData not working 0 Answers
Where is Actually The Prefabs Stored Before Instantiation? RAM or Storage(Internal Memory) 2 Answers
[CRASH] Memory can not be "read" / "write" 1 Answer
iOS VideoPlayer doesn't unload temp RenderTexture in 2019 0 Answers