Make sure you add all display objects to the sceneGroup. When a scene is removed, all objects within sceneGroup will be removed. Add objects with the following code: sceneGroup:insert(object).
Scenes are not removed from memory unless you remove them with the code: composer.removeScene(scene). You can not remove the active scene. So, if game.lua is the active scene, composer.removeScene(game) will not work. A workaround is to set up a blank scene. Let’s say its game over and you want you have a button to play again. If you simply load game.lua ontop of itself, you will have two instances of the scene loaded on the screen. It won’t work. Instead, have the play again button point to a blank scene. Within the blank scene, add a function which handles the removal of the game scene and the reloading of it. Then, set up a timer to run the function. It would look something like this.
function reLoadGame()
composer.removeScene(game)
composer.gotoScene(game)
end
timer.performWithDelay(1000, reLoadGame)
You will need to handle widget Button and event listener removal on your own, as they are not part of scene cleanup. This can be handled within the scene:destroy() function.