Null = Garbage Collected?
Monkey Forums/Monkey Programming/Null = Garbage Collected?
| ||
I have a few mini-games within my main game, and as such want to remove them from memory once the mini-game is over and the player is returned to the main game. Am I right in thinking that I just 'Null' the instance of the mini-game class and the GC will do the rest? |
| ||
Yep, pretty much - although it is target dependent when the GC will kick in though (for example every time you call "new" in Android it gives the GC a chance to execute). |
| ||
OK thanks therevills, I am having a few issues with a timer inside the mini-game class not being reset after the class has been nulled. EDIT: Fixed this using a new timer class, so I think I must have something in my code causing the problem. Thanks for the GC info, I wasn't sure if nulling the class would automatically null all references to assets etc and I just wanted to make sure there wasn't a step I was missing (like having to do each one manually) :) |
| ||
It might be a good idea to derive them all from a single base class and just have a miniGame field in the main game. |
| ||
What advantage would that give Gerry? |
| ||
Just that if all your mini-game access is through that field, you know that any old mini-game is forgotten when you write: miniGame = New Type2MiniGame() |