# Tween good practices

**URL:** <https://phaser.discourse.group/t/tween-good-practices/5987>\
**Category:** Phaser 3\
**Created:** [April 19, 2020, 5:12pm UTC](https://phaser.discourse.group/t/tween-good-practices/5987 "2020-04-19T17:12:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptaku19](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/ptaku19/32/2170_2.png) [@ptaku19](https://phaser.discourse.group/u/ptaku19)\
**Post date:** [April 19, 2020, 5:12pm UTC](https://phaser.discourse.group/t/tween-good-practices/5987/1 "2020-04-19T17:12:42Z")

</div>

Hi, I recently started to wonder if if I use the destroy method on the object to which tween is connected:

> const tween = this.tweens.add ({targets: object,  
> …  
> })

> obj.destroy()

Is there a need to remove this tween afterwards?

> tween.remove ()

Does this have any effect on performance?

---

<div class="post-metadata">

**Author:** ![Telinc1](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/telinc1/32/60_2.png) [@Telinc1](https://phaser.discourse.group/u/Telinc1)\
**Post date:** [April 19, 2020, 5:23pm UTC](https://phaser.discourse.group/t/tween-good-practices/5987/2 "2020-04-19T17:23:43Z")

</div>

Tweens are automatically cleaned up by the Tween Manager after they complete. Destroying a Game Object after you no longer need it is a good idea - it’s faster (because you’re not rendering objects that won’t ever be seen anymore) and it saves memory (because the browser can garbage-collect the object). Note that there’s no direct connection between destroying a tween (which is done automatically) and destroying a Game Object.

---

<div class="post-metadata">

**Author:** ![ptaku19](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/ptaku19/32/2170_2.png) [@ptaku19](https://phaser.discourse.group/u/ptaku19)\
**Post date:** [April 19, 2020, 6:29pm UTC](https://phaser.discourse.group/t/tween-good-practices/5987/3 "2020-04-19T18:29:31Z")

</div>

I forgot that tween is looped so

> repeat:-1

Is tween with this property cleaned up when his target is destroyed?

---

<div class="post-metadata">

**Author:** ![Telinc1](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/telinc1/32/60_2.png) [@Telinc1](https://phaser.discourse.group/u/Telinc1)\
**Post date:** [April 19, 2020, 6:50pm UTC](https://phaser.discourse.group/t/tween-good-practices/5987/4 "2020-04-19T18:50:55Z")

</div>

> [@ptaku19](#):
>
> Is tween with this property cleaned up when his target is destroyed?

It’s not. You have to stop the tween yourself with `tween.stop()`.

---

<div class="post-metadata">

**Author:** ![as3mbus](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/as3mbus/32/3328_2.png) [@as3mbus](https://phaser.discourse.group/u/as3mbus)\
**Post date:** [November 11, 2020, 7:51am UTC](https://phaser.discourse.group/t/tween-good-practices/5987/5 "2020-11-11T07:51:32Z")

</div>

sorry for necrobumping this.

but does stopping tween automatically remove it as well ?  
i am having a tween that need to be replaced when resize event is called (for responsive purpose)

is doing this fine ?

```javascript
const tween =this.tween.add(. . . )
this.scale.on('resize', () => 
{
  tween.stop();
  tween = this.tween.add(. . . )
})

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [November 11, 2020, 5:09pm UTC](https://phaser.discourse.group/t/tween-good-practices/5987/6 "2020-11-11T17:09:32Z")

</div>

It does, but not right away. In practice it may make little difference. You could use `remove()` there.

> #### stop()
> 
> Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager.

> #### remove()
> 
> Immediately removes this Tween from the TweenManager and all of its internal arrays, no matter what stage it as it. Then sets the tween state to `REMOVED` .
