I have a problem when resetting my game.
I have a couple of levels which are populated from a pool of objects using an xml file. everything works fine untill i restart a level or pick a new level. I think my models remain in memory but i do clear them.
this is how it works:
I'm declaring an array and a world so i can easily access my objects:
private List<Object3D> worldObjectsArray = new ArrayList<Object3D>();
private List<Integer> worldObjectsArrayType = new ArrayList<Integer>();//identifies the object type
private Object3D worldEnvironment = null
Then i load my world when a level is selected from the frontend:
worldEnvironment = Loader.loadSerializedObject(res.openRawResource(R.raw.levelA));
worldEnvironment.setTexture("levelAtexture");
worldEnvironment.getMesh().compress();
worldEnvironment.forceGeometryIndices(true);
worldEnvironment.build();
worldEnvironment.strip();
world.addObject(worldEnvironment);
worldEnvironment.addCollisionListener(this);
then I process an xml file and get the object type from it: (exluded the loop from example)
node = getxmlelement;//this is an xml element loaded from a loop
if (node == "buildingA") {
tempobject = new Object3D((Loader.loadSerializedObject(res.openRawResource(R.raw.buildinga))), true);
tempobject.setTexture("texturepage1");
objectType = 1;
}
if (node == "carA") {
tempobject = new Object3D((Loader.loadSerializedObject(res.openRawResource(R.raw.cara))), true);
tempobject.setTexture("vehicles");
objectType = 2;
}
tempobject.strip();
tempobject.build();
worldObjectsArray.add(tempObject);
worldObjectsArrayType.add(objectType);
world.addobject(tempObject)
tempobject = null;
which all works fine, my world is populated and I can access all objects no problem.
All transforms and data comes through from the xml fine.
but when I reset my game or game over I call reset:
if (worldObjectsArray.size() > 0) {
for (int i=worldObjectsArray.size()-1;i>=0;i--) {
if (worldObjectsArray.get(i) != null) {
world.removeObject(worldObjectsArray.get(i));
worldObjectsArray.set(i,null);//probably overkill
}
}
}
worldObjectsArray.clear();
worldObjectsArrayType.clear();
and reset the world:
world.removeObject(worldEnvironment);
worldEnvironment=null;
after this, my world.size() is zero, the array is cleared and i should have some more free ram but no.
the memory that was filled when loading the level is not cleared and it looks like the model references are kept in ram. Because when i reload the level, more ram is being used untill i eventually run out of memory and the game crashes. (I'm looking at ddms here)
If my xml file has 50 objects, i can probably restart the game about 5 times, if i have 300 objects, i can only play only once.
I've looked on the forum but cant find anything that fixes it. I've tried world.disposeAll(), removing and reloading the textures. removing mesh data, etc.
Object polygon sizes are about 100 polygons each. Serialized
Level is about 2000 polygons.
Textures are all powers of 2, no bigger than 512x512 (compressed and 4bp) probably no more that about 2 for level and 5 for the frontend
I've run out of ideas so any help would be erm.. helpful.