I have been building a game for a while (nearly done) – But the game needs a replay button and its a big task.
I know the GC is dreadful in flash, but I wanted to know if there is a way to wipe EVERYTHING as if the flash app has just begun. Clearing memory, game data – I haven’t to worry about game loading as its not really heavy on data.
Everything pretty much lives in a DataModel – but I fear if I just clear the all variables, I’ll have pockets of orphaned memory.
Any forwarding idea would be great.
cheers guys.
I would do this:
addEventListener, you are passingtruefor the “use weak references” argument.Now when you want to entirely clear your game from memory, remove GameContainer from the stage and null the reference. Memory will not immediately be released, but everything in your game will now be eligible for release. If Flash thinks it needs more memory it will trigger a GC, and the large orphaned GameContainer will be nuked. (Step 2 above will keep your event listeners from counting as references to your objects, and make sure that all self-contained objects are eligible for disposal.
Not sure what you mean about Flash’s GC being dreadful though. I can’t recall having heard of any bugs in it. It won’t nuke your objects unless you are careful with your references, but that’s true of all garbage collection.