Classic EditorGUILayout.foldout problems

@CustomEditor (myScript)

class my Editor extends Editor
{
static var show:boolean = false;

function OnInspectorGUI()
show = EditorGUILayout.Foldout(show, "Options");
     if(show)
     {
     showIcons = EditorGUILayout.Toggle("CheckMe",showIcons);
     }

if(GUI.changed){EditorUtility.SetDirty(target);}
}

You’ll need to serialize your foldout state.

The state of the foldout is saved in a boolean:

state = EditorGUILayout.Foldout (state, "My Foldout");

That boolean needs to be serializable by Unity, so it persists assembly reloads:

[SerializeField]
bool state;

But, editors are destroyed and not saved to disk when you close them, so all this data is going to get lost. If you want the state of the foldout persist after objects being destroyed, you could use EditorPrefs, ScriptableObjects or other saved-to-disk mechanism to store there your foldout state, and load it back afterwards (i.e. use OnEnable, OnDisable, OnDestroy…)