- Home /
C# Singleton destructor not called in Editor
Anyone know why the destructor of my singleton is not called in the Editor? But it's called in game?
public class MyClass
{
private static MyClass _instance;
public static MyClass Get()
{
if (_instance == null)
_instance = new MyClass();
return _instance;
}
private MyClass()
{
}
~MyClass()
{
Debug.Log("NEVER CALLED IN EDITOR BUT CALLED IN GAME");
}
}
Comment
Answer by gregzo · Jul 29, 2013 at 02:02 PM
Do you really need a destructor?
Interesting read, second answer : http://stackoverflow.com/questions/4898733/when-should-i-create-a-destructor
If you really, really must, have you tried marking your class with [ExecuteInEditMode]?
I'm just doing some test, my final implementation probably won't have a destructor. But I was curious about the lifetime of static in Editor. It seem that when we exit play mode, not everything is cleaned
Did you try [ExecuteInEdit$$anonymous$$ode]? Just curious...