While searching for a system memory leak I found the following problem with my code:
I’m using a global function with a global transitionStash I always clear with a scene change:
transitionStash={} function cancelAllTransitions() local x for x=#transitionStash,1,-1 do transition.cancel( transitionStash[x]) --print ("Transition Nr. ",x," deleted now!") transitionStash[x]=nil end transitionStash = nil transitionStash = {} performWithDelay (1,function() collectgarbage("collect") end,1) return true end
I’m using this for example inside a mainmenu scene, when clicking on a button some transitions will blend in a level selection overview inside the mainmenu. A back-button will then (also with transitions) blend out the level selection and show the original button again.
After clicking the button again the level selection overview is shown again (using transitions) and the back-button will blend the overview out again… and so on.
After doing this for about 20 times, the system memory will increase about 1MB and tests have shown it is the growing transitionStash array.
Now I wonder how I can use a transitionStash AND avoid the growing system memory?
Here is the code (function) which is called when the back-button is used to show the original main buttons again after the level selection buttons where shown:
local showmenuimagesagain = function() --blending in all the images we need for the main menu: transitionStash[#transitionStash+1]=transition.to(gfx.titlelogoshadow,{time=250,delay=1,alpha=0.08,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.titlelogo,{time=320,delay=10,alpha=1,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.btn\_newstart,{time=320,delay=50,alpha=1,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.playbtn\_txt,{time=300,delay=40,alpha=1,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.playbtn\_txtshadow,{time=300,delay=30,alpha=0.25,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.btn\_newrate,{time=320,delay=70,alpha=1,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.ratebtn\_txt,{time=300,delay=60,alpha=1,tag="newstart",transition=easing.outQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.ratebtn\_txtshadow,{time=300,delay=51,alpha=0.25,tag="newstart",transition=easing.outQuad}) fc.startinfotextanimation() transitionStash[#transitionStash+1]=transition.to(gfx.settings,{time=320,delay=80,alpha=1,transition=easing.inQuad,onComplete=function() composer.state.buttonsactive=1;transition.resume("newstart") end}) transitionStash[#transitionStash+1]=transition.to(gfx.btn\_languageselection,{time=300,delay=60,alpha=1,transition=easing.inQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.btn\_difficulty,{time=300,delay=60,alpha=1,transition=easing.inQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.difficultyicon,{time=300,delay=60,alpha=1,transition=easing.inQuad}) transitionStash[#transitionStash+1]=transition.to(gfx.flagimg,{time=300,delay=60,alpha=1,transition=easing.inQuad}) end
Calling cancelAllTransition() at scene change will clear the used memory btw.