Well, if you don’t want to look up the code I’ve attached, here are the sources:
main.lua:
local storyboard = require "storyboard" storyboard.gotoScene( "scene1" )
scene1.lua:
local storyboard = require "storyboard" local scene = storyboard.newScene() local widget = require "widget" local sheetInfo local imageSheet local testButton local unimportantImage local function onTestButtonEvent(event) end function scene:createScene( event ) local group = self.view sheetInfo = require "sheets.test" imageSheet = graphics.newImageSheet("sheets/test.png", sheetInfo:getSheet()) --- Uncomment this section to see how ButtonWidget causes Texture Memory not to be released in the next scene testButton = widget.newButton{ sheet = imageSheet, defaultFrame = sheetInfo:getFrameIndex("button\_1"), overFrame = sheetInfo:getFrameIndex("button\_2"), onEvent = onTestButtonEvent } testButton:setReferencePoint(display.CenterReferencePoint) testButton.x, testButton.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 group:insert(testButton) unimportantImage = display.newImageRect(imageSheet, sheetInfo:getFrameIndex("image\_1"), 10, 10) unimportantImage:setReferencePoint(display.TopCenterReferencePoint) unimportantImage.x, unimportantImage.y = display.contentWidth \* 0.2, display.contentHeight \* 0.2 group:insert(unimportantImage) end function scene:enterScene( event ) print("SCENE \_ 1 : Texture Memory used = ", system.getInfo("textureMemoryUsed") / 1024 .. "Kb") timer.performWithDelay(2000, function() storyboard.gotoScene("scene2") end) end function scene:exitScene( event ) end function scene:destroyScene( event ) print("SCENE \_ 1 : Destroying") if testButton then testButton:removeSelf() testButton = nil end sheetInfo = nil imageSheet = nil end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
scene2:lua:
local storyboard = require "storyboard" local scene = storyboard.newScene() local widget = require "widget" function scene:createScene( event ) local group = self.view end function scene:enterScene( event ) storyboard.removeAll() collectgarbage() timer.performWithDelay(2000, function() collectgarbage() print("SCENE \_ 2 : Texture Memory used = ", system.getInfo("textureMemoryUsed") / 1024 .. "Kb") end, 0) end function scene:exitScene( event ) end function scene:destroyScene( event ) end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene