# \[Editor 4.0.0-beta.7\] Script still running after attached mesh disposed?

**URL:** <https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882>\
**Category:** Questions\
**Tags:** editor\
**Created:** [October 13, 2020, 8:20am UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882 "2020-10-13T08:20:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vUdevU](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@vUdevU](https://forum.babylonjs.com/u/vUdevU)\
**Post date:** [October 13, 2020, 8:20am UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882/1 "2020-10-13T08:20:30Z")

</div>

So I’ve been using SceneLoader.Append to change between scenes for a project in the babylon.js editor 4.0.0-beta.7, and the script attached to a cube mesh in the scene is still calling onUpdate() despite calling dispose() before the scene change. (still printing to console from onUpdate)

I wrote a test script attached to the cube to test it

> export default class TestDispose extends Node {
> 
> private constructor() { }
> 
> public onInitialize(): void {}
> 
> public onStart(): void {  
> this.getScene.meshes.forEach((value, index, array\> {Logger.Log("Mesh Name: " + value.name);}
> 
> SceneLoader.Append(“…/…/scenes/theOtherScene/”, “scene.babylon”, this.getScene(), (scene)=\>{  
> var scripts = { “src/scenes/theOtherScene/foo.ts” : require(“…/theOtherScene/foo.ts”),}  
> attachScripts(scripts, scene);  
> scene.meshes.forEach((value, index, array\> {Logger.Log("Mesh Name: " + value.name);})  
> });
> 
> //Remove meshes  
> for (var i = 0; i \< this.getScene().meshes.length; ++i){  
> this.getScene().meshes[i].dispose();  
> –i;  
> } //remove meshes for  
> } //onStart
> 
> public onUpdate(): void {  
> Logger.Log(“I’m alive”);  
> }
> 
> }//TestDispose

Printing out the list of meshes in the scene before and after the scene change also shows that the cube is no longer in the getScene().meshes, but the script attached to it continues to call onUpdate, printing out “I’m alive”.

I’m not sure if there’s a way to explicitly remove and destroy a script, or if there’s more to disposing the mesh to remove the script. I may be in over my head, as I’m not familiar with how garbage collection works in Typescript/Javascript, so I’m not sure how to proceed from here.

Is there a method provided by the editor to explicitly detach or destroy scripts already attached? Do I just need to delete the object generated by the script?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [October 13, 2020, 8:49am UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882/2 "2020-10-13T08:49:38Z")

</div>

Pinging @julien-moreau

---

<div class="post-metadata">

**Author:** ![julien-moreau](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/julien-moreau/32/12070_2.png) [@julien-moreau](https://forum.babylonjs.com/u/julien-moreau)\
**Post date:** [October 14, 2020, 4:53pm UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882/3 "2020-10-14T16:53:28Z")

</div>

Hey @vUdevU! Nice catch!! Thanks for reporting!  
Just fixed and fix is available on branch release/4.0.0 (here: [GitHub - BabylonJS/Editor at release/4.0.0](https://github.com/BabylonJS/Editor/tree/release/4.0.0)). Can you build the Editor yourself or do you need a release ASAP?

---

<div class="post-metadata">

**Author:** ![vUdevU](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@vUdevU](https://forum.babylonjs.com/u/vUdevU)\
**Post date:** [October 15, 2020, 2:42am UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882/4 "2020-10-15T02:42:58Z")

</div>

I would greatly appreciate a release! I haven’t tried building the editor myself yet, but I can work on some other parts of my project while waiting for a release. Thanks!

---

<div class="post-metadata">

**Author:** ![julien-moreau](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/julien-moreau/32/12070_2.png) [@julien-moreau](https://forum.babylonjs.com/u/julien-moreau)\
**Post date:** [October 19, 2020, 7:19pm UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882/5 "2020-10-19T19:19:06Z")

</div>

Hey @vUdevU, just released!  
You’ll be notified by the Editor or you can simply download the update here: [BabylonJS Editor v4.0.0 beta · BabylonJS/Editor Wiki · GitHub](https://github.com/BabylonJS/Editor/wiki/BabylonJS-Editor-v4.0.0-beta) 🙂

Don’t hesitate if you encouter any other bug or want to suggest some improvements / feature requests 🙂

---

<div class="post-metadata">

**Author:** ![vUdevU](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@vUdevU](https://forum.babylonjs.com/u/vUdevU)\
**Post date:** [October 20, 2020, 6:32am UTC](https://forum.babylonjs.com/t/editor-4-0-0-beta-7-script-still-running-after-attached-mesh-disposed/14882/6 "2020-10-20T06:32:46Z")

</div>

Thank you!! And thank you for your quick responses and fixes!
