空的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()
    {
        
    }
}
相關文章
相關標籤/搜索