Memory leaks?

Hello guys!

I have a simple question,

If I create an instance of some class in a function, for example in OnInspectorGUI, will it be automatically destroyed at the end of function?
Or do I have to personally destroy it?

Thank you

Mono is the opensource version of DotNet. Yes, the Garbage Collector will do its job and will claim the memory of any dangling node automatically.

Yeah, but you can call GC manually though, but it’s really not suggested as it will broke it’s current processing order.

Also, this is the reason why locally created variables are more better than in class. As variables declared inside class will always be reserved in memory, but when created in method, those variables will be created (memory reserved for them) in a blink of an eye, and when function- method ends, everything is freed by GC.
Of course, you can’t do it for everything, but it’s still a good thing to remember if you really care about optimizations.