- Home /
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
Answer by YoungDeveloper · Dec 31, 2013 at 06:23 PM
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.
Answer by Subhajit-Nath · Dec 31, 2013 at 06:17 PM
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.
Your answer
Follow this Question
Related Questions
how do I remove a class item from a list? 1 Answer
Why are objects just set to null? 2 Answers
Memory leak with Streaming terrains 0 Answers