I’m developing a game for platforms with very strict memory limits using Unity, and I’m running into serious memory usage issues. I need to have more specific information on where the memory is being allocated during runtime. The unity profiler only provides these stats:
Total Allocated
Texture Memory
I need much more detailed information (what variables are not being deallocated, what textures are using up all the texture memory).
Does anyone have an idea how can I get this information? Are there external tools for this?
I also have a similar problem. I need more detailed information.
Also, actual memory used on the iOS device doesn’t correspond to the reported numbers from the Unity memory profiler.
I’m trying to measure the memory usage of various prefabs in my game. If you observe the Memory Profiler when loading a prefab you can see the various memory types go up (meshes, textures, anims, audio, etc), but how do I access this information from code?
The only memory total I can find is System.GC.GetTotalMemory(true) but that appears to only show heap memory and none of the specialized memory pools that the profiler reports upon. I’d settle for editor only functions like…
long mem1 = EditorUtility.GetTextureMemory();
long mem2 = EditorUtility.GetMeshMemory();
You could use Object.FindObjectsOfType(typeof(Whatever)).Length to get the number of objects of type Whatever.
As far as measuring the memory usage of individual textures and meshes goes, you have to do that yourself. For example, the bytes used by a texture are (width * height * bytes_per_pixel) * (texture_has_mipmaps ? 4f/3f : 1).