空的OnGUI也会有gc

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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    private void OnGUI()
    {
        
    }
}

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

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()
    {
        
    }
}
相关文章
相关标签/搜索