空的OnGUI也会有gc

时间:2023-03-09 08:25:02
空的OnGUI也会有gc

一个空场景,添加如下代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class NewBehaviourScript : MonoBehaviour
{
private void OnGUI()
{ }
}

空的OnGUI也会有gc

可以看到每帧有一个固定的内存gc,可以用useGUILayout开关来关闭其gc消耗:

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class NewBehaviourScript : MonoBehaviour
{
private void Start()
{
#if !UNITY_EDITOR
useGUILayout = false;
#endif
} private void OnGUI()
{ }
}