Where is the best place to call purgeScene() when exiting a scene?

I have a scene, let’s say “ABC”, and it has a “back button”.

When the back button is clicked, scene “ABC” should be destroyed and the app goes to another scene.

Where is the best place to call purgeScene(“ABC”) in scene ABC after the back button is clicked?

I used to call it in exitScene() in ABC, but it seems not a good place.

Any suggestion?

I think the only place you can put it is in exitScene().  But personally, depending on how your storyboards are structured, I would purge it in the scene I just went to if I could.  You probably could get the previous scene name and then purge it in the new scene’s enterScene() function (maybe even put it in a 1-2 second timer so the purge doesn’t slow down the start of the level).  If you can’t do it that, way, the other thing I like to do is purge before I go to the scene.   I’ll do the purge right before the gotoScene.

If you always want to purge, you can set a flag in main.lua after you require storyboard that turns on auto purging and then you don’t have to worry about it.

My app made a lot of network.request() calls, and I didn’t pay much attention about the timing of the network listener callbacks. For example, the callback might happen after the scene is gone or in a more complicated condition, the callback might come after the scene is destroyed and gets created again (but with different scene parameters now). 

Thanks for the suggestions and I think everything is fine now.

I think the only place you can put it is in exitScene().  But personally, depending on how your storyboards are structured, I would purge it in the scene I just went to if I could.  You probably could get the previous scene name and then purge it in the new scene’s enterScene() function (maybe even put it in a 1-2 second timer so the purge doesn’t slow down the start of the level).  If you can’t do it that, way, the other thing I like to do is purge before I go to the scene.   I’ll do the purge right before the gotoScene.

If you always want to purge, you can set a flag in main.lua after you require storyboard that turns on auto purging and then you don’t have to worry about it.

My app made a lot of network.request() calls, and I didn’t pay much attention about the timing of the network listener callbacks. For example, the callback might happen after the scene is gone or in a more complicated condition, the callback might come after the scene is destroyed and gets created again (but with different scene parameters now). 

Thanks for the suggestions and I think everything is fine now.