Merry Christmas All,
I was just wondering what I need to do with modules concerning memory management. I am using storyboards and just wanted to know if I need to nil things out or remove Event Listeners?
For example in the generic back button example below, when the button is pressed do I need to remove the listener? What about the graphics? Or are these automatically cleaned up when the storyboard scene transitions off? My worry is that when I use the same module on the next scene that this ‘copy’ is left hanging around and could be causing a memory leak… This is a very simple example, but I have some modules that are rather big, and could cause memory issues if they are left hanging around.
Thanks in advance, and again Merry Christmas…
Craig
main.lua (from enter scene)
[lua]
local utilitiesClass = require ( “Classes.utilities” )
local backButton = utilitiesClass:backButton()
Group:insert(backButton)
[/lua]
utilities.lua
[lua]
local utilities = {}
function utilities:tap(event)
if event.target.id == “backButton” then
local lastScene = storyboard.returnTo
print( “previous scene”, lastScene )
if ( lastScene ) then
storyboard.gotoScene( lastScene, { effect=“fade”, time=500 , params = event.target.params} )
end
end
end
function utilities:backButton(params)
self.backButtonIcon = display.newImageRect( “Images/backButton.png”, 80, 80 )
if params then
self.backButtonIcon.params = params
else
self.backButtonIcon.params = nil
end
self.backButtonIcon.id = “backButton”
self.backButtonIcon:addEventListener(“tap”, self)
return self.backButtonIcon
end
return utilities
[/lua]