ManagedStaticReferences prevents objects to be cleared from memory.

I am trying to unload resources from my scene using Object.Destroy(). Most of the resources are unloaded correctly, but some remain. According to Unity profiler those remaining objects are only referenced by ManagedStaticReferences() and/or MonoManager. How can I remove those references or correct my code so that those leftover objects won’t be referenced by ManagedStaticReferences in the first place?

If you use singletons and static variable to store your monobehaviour, you need to set your static variable to null when the object is destroyed otherwise, all the Prefab or assets linked to this monobehaviour will not be released.

public abstract class MonoSingleton<T> : MonoBehaviour 
	where T : MonoSingleton<T>
{
    protected static T s_Instance = null;
    public static T Instance
    {
        get
        {
            if( s_Instance == null )
            {
                s_Instance = GameObject.FindObjectOfType(typeof(T)) as T;
            }
            return s_Instance;
        }
    }

	protected virtual void OnDestroy()
	{
		if (s_Instance == this)
		{
			s_Instance = null;
		}
	}
}

You must also unsubscribe from all events which can lock resources. Example:

using UnityEngine;
using System;

public class TestClass {
	public static Action mustBeCleared = null;

	public void exampleFunc(Texture texture) {
		mustBeCleared = delegate() {
			Debug.Log(texture.name);
		};
		Application.LoadLevel("another level");
	}
}

In this example function “exampleFunc” will lock your Texture in ManagedStaticReferences until you set

TestClass.mustBeCleared = null;

Thank you very much, the first answer may work.

Thanks this saved my ass pretty much.

Always set your singleton instance to null when OnDestroy is fired.

Unity should document ManagedStaticReferences. I am having the same problem even without using singletons.

When loading and instantiating a prefab that has some sprites and destroying them after, the textures of the sprites remain in the profiler with the only references referring to their asset prefabs or ManagedStaticReferences.