Hey!
Im a new at both corona and programming in general - but LOVING it! I have spent ALOT of hours learning from tuts and forums and can do some nice lines of code :)
BUT - i have a problem! I realised this problem when going back and forth between two scenes in an app i made which made the program crasch!
so i did a test app. just two (well three if you count main) scenes with two buttons, platBtn and a backBtn. Spent Alot of days trying to figure out how to propperly nil out everything.
The result?
The.Same.Craching.Program!!
The code::::
*********************************************************************************************************************************
main.lua
local composer = require(“composer”)
composer.gotoScene(“menu”)
*********************************************************************************************************************************
*********************************************************************************************************************************
menu.lua
----// Composer thingy
local composer = require( “composer” )
local scene = composer.newScene()
– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called.
----// in order to make the listener work!
local mpp
---------------------------------------------------------------------------------------------------- “scene:create()”
function scene:create( event )
local sceneGroup = self.view
----// just the PLAY btn
mpp = display.newImageRect( “mainmenu_play_pressed.png”, 195, 46 )
mpp.x = display.contentCenterX
mpp.y = display.contentCenterY
sceneGroup:insert(mpp)
end
---------------------------------------------------------------------------------------------------- “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
----// Play btn pressed
local function playPressed (event)
if event.phase == “began” then
composer.gotoScene(“settings”)
return true
end
end
----// and the play listener
mpp:addEventListener ( “touch”, playPressed )
end
end
---------------------------------------------------------------------------------------------------- “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
------------------------------------------------------------------------------------------------------ “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
----// trying to remove obj:listener
mpp:removeEventListener ( “touch”, playPressed )
----// trying to remove the play btn from mem
display.remove( mpp )
mpp = nil
----// Not sure, need to remove composer require from mem?
composer = nil
----// tryin to nil functions…
playPressed = nil
end
------------------------------------------------------------------------------------------------------ Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
*********************************************************************************************************************************
*********************************************************************************************************************************
settings.lua
----// Composer thingy
local composer = require( “composer” )
local scene = composer.newScene()
– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called.
----// in order to make the listener work!
local backbutton2
-------------------------------------------------------------------------------------------------------- “scene:create()”
function scene:create( event )
local sceneGroup = self.view
----// just the BACK btn
backbutton2 = display.newImageRect( “backbutton.png”, 51, 48 )
backbutton2.x = display.contentCenterX
backbutton2.y = display.contentCenterY
sceneGroup:insert(backbutton2)
end
-------------------------------------------------------------------------------------------------------- “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
----// Back btn pressed
local function back (event)
if event.phase == “began” then
composer.gotoScene(“menu”)
return true
end
end
----// back btn pressed: eventListener
backbutton2:addEventListener ( “touch”, back )
end
end
-------------------------------------------------------------------------------------------------------- “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
-------------------------------------------------------------------------------------------------------- “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
----// trying to remove obj:listener
backbutton2:removeEventListener ( “touch”, back )
----// trying to remove the back btn from mem
display.remove( backbutton2 )
backbutton2=nil
----// Not sure, need to remove composer require from mem?
composer = nil
----// tryin to nil functions…
back = nil
end
-------------------------------------------------------------------------------------------------------- Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
***********************************************************************************************
There are the three files: main, menu and settings and if you try to run the program and repeatedly press the btns everything will crach!
Obviously you need to include a backbutton.png and a mainmenu_play_pressed.png
Questions:
How do i fix this and whats going wrong?
* When using a memory function memory goes up to 4000KB + and just freezes 
* Using the composer template.