Did anyone run into a memory leak like this and found how to fix it? Tested under Unity 5.1.1f1 (Windows 10)
Add this to an editor script, place a sprite in the sprite field and see Unity memory usage increase with each frame.
My actual problem is a bit more complicated than this and does not even use the scene view to render the UI but a very custom UI rendered in the OnGUI() of an EditorWindow. This was just the easiest way to demonstrate this problem with ObjectField.
[InitializeOnLoad]
public class GlobalStaticTest
{
private static Sprite test;
static GlobalStaticTest()
{
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
private static void OnSceneGUI(SceneView sceneView)
{
Handles.BeginGUI();
GUILayout.BeginArea(new Rect(0, 0, 200, 200));
{
test = (Sprite)EditorGUILayout.ObjectField("test", test, typeof(Sprite), false);
}
GUILayout.EndArea();
Handles.EndGUI();
}
}
Here is another example. It even happens in a test like this. If the EditorGUILayout.ObjectField() was in the OnInspectorGUI() then it would be fine.
public class TEST_OBJECT : MonoBehaviour
{
public Sprite test;
}
// ....
[CustomEditor(typeof(TEST_OBJECT))]
public class TEST_OBJECT_Inspector : Editor
{
public override void OnInspectorGUI()
{
}
protected void OnSceneGUI()
{
Handles.BeginGUI();
GUILayout.BeginArea(new Rect(0, 0, 200, 200));
{
TEST_OBJECT Target = (TEST_OBJECT)target;
Target.test = (Sprite)EditorGUILayout.ObjectField("test", Target.test, typeof(Sprite), false);
}
GUILayout.EndArea();
Handles.EndGUI();
}
}
Doing it in the normal/ basic way, like this, causes no problems.
public class TestWindow : EditorWindow
{
private static Sprite test;
[MenuItem("Window/Test")]
public static void Show_TestWindow()
{
EditorWindow.GetWindow<TestWindow>("Test");
}
protected void OnGUI()
{
test = (Sprite)EditorGUILayout.ObjectField("test", test, typeof(Sprite), false);
}
}