How to destroy and recreate a scene in andengine correctly?

In andAngine I need to destroy a Scene in andangine and to recreate it in order to restart the game variables and listeners and gamelogic. i use this code:

scene.detachChildren();
scene.clearEntityModifiers();
scene.clearTouchAreas();
scene.clearUpdateHandlers();

System.gc();
thisengine.setScene(menuscene);

and then I recreate the scene

scene = new Scene();
scene.dosomestuff
thisengine.setScene(scene);

Something seems to go wrong when I recreate the third time the scene. Sprites doesn't display..are distorted or something doesn't display at all. Can anyone explain to me if I correctly initialize and destroy the scene ?

Answers


Personally, I would create the scene once the first time it is used.

To change the scene, do your removal stuff as you've shown, I wouldn't bother with the call to System.gc(), and then instead of creating a new Scene() - just call scene.reset(), scene.dosomestuff, etc

Creating a new Scene like you show looks like a major memory leak, or at least a possible leak.


Need Your Help

SQL performance

sql sql-server sql-server-2008 sql-server-2012 sql-server-performance

I have replaced my old processor with a Xeon processor . I don't have hyper threading. My old processor had hyperthreading and was working fine.

Creating a simple VS2008 visualizer inside autoexp.dat (problem with casting)

c++ visual-studio-2008 casting visualizer

I have a large project of mixed C/C++. I've created a simple visualizer for the ICU UnicodeString class as follows...