Hey guys !
I’m a newbie corona developer and as i was trying to create a small prototype app with only 2 scenes using storyboards. My app basically only shows one button on each scene, allowing to transition to the other scene (A has a button going to B, B has a button going to A).
While carefully monitoring the memory, i have noticed that memory was steadily increasing as i was going back and forth between the 2 scenes.
I have stripped down my code to the bare minimum i think, basically one main.lua (only loading constants / storyboard and calling gotoscene(debug1), one debug1.lua and one debug2.lua, debug1 / debug2 being the 2 “scenes”.
I used the storyboard template found in the documentation, and was quite wary of using only local variables / functions and niling everything around but still, the memory keeps increasing even though it’s by a relatively small amount.
Here is the content of a debug1.lua file:
----------------------------------------------------------------------------------------- -- -- debug1.lua -- ----------------------------------------------------------------------------------------- local screenName = "debug1" local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- include Corona's "widget" library local widget = require "widget" -------------------------------------------- -- Current screen name local groupObj = nil local btn = nil -- event listeners ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- local function onTransitionBtnRelease(event) local btn = event.target local toScene = btn.params["toScene"] print("Before go to scene on "..screenName) storyboard.gotoScene( scenes..toScene, "fade", 1) return true end local function createTransitionButton(text, gx, gy, gwidth, gheight, toScene, clearOldScene) -- transition button (from a scene to a new one) btn = widget.newButton{ label=text, labelAlign = "center", font = "Arial", fontSize = 18, labelColor = { default = {0,0,0}, over = {255,255,255} }, width=gwidth, height=gheight, onRelease = onTransitionBtnRelease -- event listener function } btn:setReferencePoint( display.CenterReferencePoint ) btn.x = gx btn.y = gy btn.params = {} btn.params["toScene"] = toScene groupObj:insert( btn ) end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view print ("create "..screenName) groupObj = group createTransitionButton("Debug2", display.contentWidth\*0.5, display.contentHeight - 50, 154, 40, "debug2", true) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view print ("exit "..screenName) storyboard.removeScene(scenes..screenName) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view print ("destroy "..screenName) display.remove(btn) groupObj = nil btn.params = nil btn = nil end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene
My memory checking function is:
local function checkMemory() collectgarbage( "collect" ) local memUsage\_str = string.format( "MEMORY = %.3f KB", collectgarbage( "count" ) ) print( memUsage\_str, "TEXTURE = "..(system.getInfo("textureMemoryUsed") / (1024 \* 1024) ) ) end timer.performWithDelay( 1000, checkMemory, 0 )
Am i doing anything wrong ? I really do not know where this is coming from 
If anyone could give me a hint or anything i would be very very thankful :))
Cheers,
Teddy
i guess)…