Question

i found a problem in my app: a have to scenes S1 and S2 and manager M; from S1 i can build and switch to S2 and from S2 can get S1 (all through manager).

Each time when i switch between scenes i want to delete one of it.

But i found that if i switch between scenes both scenes store in memory and after many switches app is crashed.

some pseudocode:

Manager:

    void build(Scene s){
    getEngine().setScene(s);
    }

    onLoadScene{
    M.build(S1);
    }

S1:

    onButtonClick{
    M.build(S2);
    }

S2:

    onButtonClick{
    M.build(S1);
    }

As i think when i build S1 link to S2 is dissapeared and when build S2, S1 dissapeard and GC have to clean it if memory is not enough.

How can i avoid crashes of application?

Thx a lot.

Was it helpful?

Solution

That's not enough code to help you find a memory leak. But my guess is your textures are getting recreated, and your sprites remain attached to the scenes. You want to pool and re-use your resources. Check for every time you are calling "new" anything, or creating a textureAtlas. In those cases make some sort of class that stores the old instances and reinitializes them. Andengine can be very sticky with resources unless you can specifically remove each one and all fo its references and dependencies. However in most games there is a limit on the number of bullets, enemies, bg tiles, etc that you need. So its possible to set up pools for each object type and recycle them. Waht you DONT want to do is make new assets each time you cal build().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top