释放 ProfilerRecorder 的非托管实例。
当您不再需要使用 ProfilerRecorder 时,始终使用此方法安全地释放其实例。
using Unity.Profiling; using UnityEngine;
public class ExampleScript : MonoBehaviour { ProfilerRecorder systemMemoryRecorder; ProfilerRecorder gcMemoryRecorder; ProfilerRecorder mainThreadTimeRecorder;
void OnEnable() { systemMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "System Used Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately); gcMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "GC Reserved Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately); mainThreadTimeRecorder = new ProfilerRecorder(ProfilerCategory.Internal, "Main Thread", 15); mainThreadTimeRecorder.Start(); }
void OnDisable() { systemMemoryRecorder.Dispose(); gcMemoryRecorder.Dispose(); mainThreadTimeRecorder.Dispose(); } }