Hi!
I’m making a tile based car game, and I have some problems… When deleting dynamically added houses from the stage, there is happenig some memory leaks. Here is some code:
Here I make the House:
/* When updating the tile, I check if there must be a house on it. And if there should be one, I make it like this*/
var house:House = new House(num);
house.x = tile.x;
house.y = tile.y;
tile.addHouse(house); /*Doing this, because tile must know if it has house on it */
ground.addChild(house);
And here I try to delete it:
/*In root I have this code: */
tile.deleteHouses();
/*calling delete function from tile, because the tile know which house must be deleted */
/* In tile I have this deletefunction */
public function deleteHouses():void{
if(house!==null)
house.deleteSelf(); //house has it's own delete function
house = null;
}
/* House's delete function */
public function deleteSelf():void{
parent.removeChild(this);
}
When driving few minutes, program slows down, and when calling this:
var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + "Mb";
trace( mem );
the total memory is growing up.
Houses are 3d-objects, but I don’t know if it affects…
I’d be glad if somebody understands my description