long Unity 分配的内存量。如果 Profiler 不可用,则会返回 0。
Unity 中由内部分配器分配的内存总数。Unity 从系统中保留了大内存池;这包括纹理所需的两倍内存,因为 Unity 会同时在 CPU 和 GPU 上保留每种纹理的副本。此函数会返回该池中已用内存量。
using UnityEngine; using UnityEngine.Profiling;
public class Example : MonoBehaviour { void Update() { Debug.Log("Total Reserved memory by Unity: " + Profiler.GetTotalReservedMemoryLong() + "Bytes"); Debug.Log("- Allocated memory by Unity: " + Profiler.GetTotalAllocatedMemoryLong() + "Bytes"); Debug.Log("- Reserved but not allocated: " + Profiler.GetTotalUnusedReservedMemoryLong() + "Bytes"); } }