How do I close the 'System.Threading.Timer' in my UnityEditor

I always use background threads to do some certain things.
When I stop my unity3d, I find that freeing memory isn’t done during the debugging. Why isn’t freeing memory be done? How do I free the memory?

1 Answer

1

Have you tried Dispose()?

timer.Dispose();

but.... When I stoped the u3dEditor. You know I can't do that:'timer.dispose()' And, when I stoped u3dEditor I saw the run of log is printting, if I used the Timer in my code. I mean the log of "Console view"

timer.Stop() maybe? or timer.enabled = false

If you need to detect when your application is about to quit so you can call timer.Dispose(), put the following method in the script that is using the timer. C# void OnApplicationQuit() { timer.Dispose(); } JavaScript function OnApplicationQuit() { timer.Dispose(); }

Thank you. Are the 'OnApplicationQuit()' only for UnityEditer ?

No, OnApplicationQuit will be called in standalone, web player, or in the Editor when you stop play mode. See [reference][1]. [1]: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnApplicationQuit.html