I am trying to track down a memory leak in my app, and I am having quite a hard time.
Below is code for 2 scenes which, when you switch between them, add to the memory usage slightly. I keep on doing this and the memory just NEVER goes down! What am I doing wrong here?
PS: Both basically only has a clickable image that alternates going from one to the other.
menu.lua:
[lua]local storyboard = require(“storyboard”);
local scene = storyboard.newScene();
storyboard.state = {}
function scene:createScene(e)
local view = self.view
local function onAdTap( self, event )
if (event.phase == “began”) then
storyboard.gotoScene( “about” )
end
end
local ad = display.newImageRect(“adsample.png”, _W, 64)
ad:setReferencePoint(display.CenterReferencePoint);
ad.x = _W/2 ad.y = _H/2
ad.touch = onAdTap – the function we created previously
ad:addEventListener( “touch” )
view:insert(ad);
end
function scene:exitScene(e) storyboard.removeScene(“menu”) end
function scene:enterScene(e)
local monitorMem = function()
collectgarbage()
print( "MemUsage: " … collectgarbage(“count”) )
local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
print( "TexMem: " … textMem )
end
Runtime:addEventListener( “enterFrame”, monitorMem )
local prior_scene = storyboard.getPrevious()
if (prior_scene) then
storyboard.purgeScene( prior_scene )
end
end
scene:addEventListener(“enterScene”, scene);
scene:addEventListener(“createScene”, scene);
scene:addEventListener(“exitScene”, scene);
return scene;[/lua]
about.lua:
[lua]local storyboard = require(“storyboard”);
local scene = storyboard.newScene();
function scene:createScene(e)
local view = self.view
local function onAdTap( self, event )
if (event.phase == “began”) then
storyboard.gotoScene( “menu” )
end
end
local ad = display.newImageRect(“adsample.png”, _W, 64)
ad:setReferencePoint(display.CenterReferencePoint);
ad.x = _W/2 ad.y = _H/2
ad.touch = onAdTap – the function we created previously
ad:addEventListener( “touch” )
view:insert(ad);
end
function scene:exitScene(e) storyboard.removeScene(“about”) end
function scene:destroyScene(event) end
function scene:enterScene(e)
local prior_scene = storyboard.getPrevious()
if (prior_scene) then
storyboard.purgeScene( prior_scene )
end
end
scene:addEventListener(“enterScene”, scene);
scene:addEventListener(“destroyScene”, scene )
scene:addEventListener(“createScene”, scene);
scene:addEventListener(“exitScene”, scene);
return scene;[/lua]
Please help.
Thank you so much.
John
PS: I have read these:
- http://www.coronalabs.com/blog/2012/08/21/storyboard-basic-usage/
- http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/
And have tried to see if they help but to no avail. 
I even set:
[lua]storyboard.purgeOnSceneChange = true[/lua] [import]uid: 186198 topic_id: 32700 reply_id: 332700[/import]
