Does variables, timers and eventListeners removed during scene change?

Hello,

As the title says, does the storyboard scene change removes everything including local and global variables, timers and all the eventListeners?

Thanks

If you do not purge or remove the scene, the entire scene hangs around unless you explicitly clear it.

If you call storyboard.purgeScene() (or purgeAll() or have autopurge on), then any display object that has been added to the scene’s view (i.e. it’s group) will be destroyed.   If there are eventListeners like touch handlers, tap handlers etc. on objects that have been inserted into the view, when they are destroyed you can no longer interact with the touch handlers, so they are in effect removed.  The functions that handle the touch handlers are part of your code base and don’t need to be deallocated or anything. 

However, any variables local to the scene’s module’s main chunk will retain their values.  It’s kinda hard to explain how local variables inside of functions automatically go away when the function goes away because many times you’re dealing with pointers to allocated memory and those pointers can be returned to the caller or stored in other variables out side of the function. 

Global variables (which we highly encourage you to not use) will hang around for the duration of your program.  Even if you use an external module to hold your data as recommended for “global like” data, it will be retained as long as that module has not been unrequired.

Timers, transition pointers, physics bodies, audio handles, Runtime eventListeners (not object), are not removed.  Any onComplete attached to an audio play, timer, transition, etc. will continue to execute after exiting a scene.  If you remove the scene or cause any of the display objects required for that onComplete to run by purging the scene you could hard crash your app.

If you call purgeScene() only those display objects added to the scene’s view (group), generally in the createScene() function, will be removed.  If you call removeScene() then you will in effect “unrequire” the module.  This removes everything in the scene, though Runtime listeners, physics still running etc. will survive beyond it. 

Hope that helps

Rob

If you do not purge or remove the scene, the entire scene hangs around unless you explicitly clear it.

If you call storyboard.purgeScene() (or purgeAll() or have autopurge on), then any display object that has been added to the scene’s view (i.e. it’s group) will be destroyed.   If there are eventListeners like touch handlers, tap handlers etc. on objects that have been inserted into the view, when they are destroyed you can no longer interact with the touch handlers, so they are in effect removed.  The functions that handle the touch handlers are part of your code base and don’t need to be deallocated or anything. 

However, any variables local to the scene’s module’s main chunk will retain their values.  It’s kinda hard to explain how local variables inside of functions automatically go away when the function goes away because many times you’re dealing with pointers to allocated memory and those pointers can be returned to the caller or stored in other variables out side of the function. 

Global variables (which we highly encourage you to not use) will hang around for the duration of your program.  Even if you use an external module to hold your data as recommended for “global like” data, it will be retained as long as that module has not been unrequired.

Timers, transition pointers, physics bodies, audio handles, Runtime eventListeners (not object), are not removed.  Any onComplete attached to an audio play, timer, transition, etc. will continue to execute after exiting a scene.  If you remove the scene or cause any of the display objects required for that onComplete to run by purging the scene you could hard crash your app.

If you call purgeScene() only those display objects added to the scene’s view (group), generally in the createScene() function, will be removed.  If you call removeScene() then you will in effect “unrequire” the module.  This removes everything in the scene, though Runtime listeners, physics still running etc. will survive beyond it. 

Hope that helps

Rob