# Memory leak

**URL:** <https://forum.kirupa.com/t/memory-leak/325172>\
**Category:** Uncategorized\
**Created:** [September 29, 2011, 7:44pm UTC](https://forum.kirupa.com/t/memory-leak/325172 "2011-09-29T19:44:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johku90](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@Johku90](https://forum.kirupa.com/u/Johku90)\
**Post date:** [September 29, 2011, 7:44pm UTC](https://forum.kirupa.com/t/memory-leak/325172/1 "2011-09-29T19:44:36Z")

</div>

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:

```auto

/* 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:

```auto

/*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:

```auto

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 🙂
