# BitmapData don't destroy

**URL:** <https://phaser.discourse.group/t/bitmapdata-dont-destroy/400>\
**Category:** Phaser 2 / CE\
**Created:** [December 20, 2018, 1:34am UTC](https://phaser.discourse.group/t/bitmapdata-dont-destroy/400 "2018-12-20T01:34:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![damager](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@damager](https://phaser.discourse.group/u/damager)\
**Post date:** [December 20, 2018, 1:34am UTC](https://phaser.discourse.group/t/bitmapdata-dont-destroy/400/1 "2018-12-20T01:34:01Z")

</div>

I’m dynamically creating textureAtlas based on bitmapdata.canvas. When the level is over i destroy that bitmapdata and also remove textureAtlas via `this.game.cache.getBaseTexture("textureAtlasName").destroy();`.  
But memory is still growing up. What can it be?

---

<div class="post-metadata">

**Author:** ![nazimboudeffa](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nazimboudeffa/32/282_2.png) [@nazimboudeffa](https://phaser.discourse.group/u/nazimboudeffa)\
**Post date:** [December 20, 2018, 3:05am UTC](https://phaser.discourse.group/t/bitmapdata-dont-destroy/400/2 "2018-12-20T03:05:06Z")

</div>

Maybe `destroy()` doesn’t supress it from the cache and maybe there is another function to do it

---

<div class="post-metadata">

**Author:** ![damager](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@damager](https://phaser.discourse.group/u/damager)\
**Post date:** [December 20, 2018, 3:12pm UTC](https://phaser.discourse.group/t/bitmapdata-dont-destroy/400/3 "2018-12-20T15:12:24Z")

</div>

I also use  
`this.game.cache.removeTextureAtlas("puzzleAtlas");`  
And i don’t know why it’s still in memory.  
Funny moment: When i change state from Level to Menu last texture atlas clears from memory. but if i change state from Level to Level(restarting it) then i have stacked textureatlases in memory

---

<div class="post-metadata">

**Author:** ![nazimboudeffa](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nazimboudeffa/32/282_2.png) [@nazimboudeffa](https://phaser.discourse.group/u/nazimboudeffa)\
**Post date:** [December 20, 2018, 4:21pm UTC](https://phaser.discourse.group/t/bitmapdata-dont-destroy/400/4 "2018-12-20T16:21:38Z")

</div>

If you use destroy in one of the predefined methods in a state it will destroy the Game Object. It means removes it from its parent group, destroys the input, event and animation handlers if present  
and nulls its reference to `game` , freeing it up for garbage collection.  
According to [the documentation](https://photonstorm.github.io/phaser-ce/Phaser.Component.Destroy.html)

There are some predefined methods in Phaser CE  
init  
preload  
loadUpdate  
loadRender  
create  
update  
preRender  
render  
resize  
paused  
resumed  
pauseUpdate  
shutdown

Maybe the reference of the game object is destroyed specifically in one of these methods

---

<div class="post-metadata">

**Author:** ![damager](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@damager](https://phaser.discourse.group/u/damager)\
**Post date:** [December 20, 2018, 4:45pm UTC](https://phaser.discourse.group/t/bitmapdata-dont-destroy/400/5 "2018-12-20T16:45:58Z")

</div>

Thanks for you answer, but the question is still why they are not disappear on Level to Level, just on Level to Menu. I try to keep destroy method on every my class and clean up everything. But may be i need to recheck all my classes on correct destruction.
