Memory Leak With Newtext()

I am gaining 32,768 bytes every time I enter a scene with storyboard. I have traced it down to display.newText()

local storyboard = require("storyboard") local scene = storyboard.newScene() function scene:createScene(e) local view = self.view local btnNext = display.newRect(\_W\*0.5,\_H\*0.5,60,60) btnNext:setFillColor(0,150,0) local txtTitle = display.newText("Test of memory leak",0,0,native.systemFont,32) txtTitle.x=\_W\*0.5 txtTitle.y=\_H\*0.88 txtTitle:setTextColor(0,102,0) local function gotoScene() storyboard.gotoScene("moduleRelaxedMenu") end btnNext:addEventListener("tap",gotoScene) view:insert(btnNext) view:insert(txtTitle) end function scene:enterScene(e) print("Enter Home: "..system.getInfo( "textureMemoryUsed" )) end function scene:exitScene(e) storyboard.purgeScene("moduleHome") print("Exit Home: "..system.getInfo( "textureMemoryUsed" )) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) return scene

If I remark out

    --local txtTitle = display.newText(“Test of memory leak”,0,0,native.systemFont,32)
    --txtTitle.x=_W*0.5
    --txtTitle.y=_H*0.88
    --txtTitle:setTextColor(0,102,0)

and

    --view:insert(txtTitle)
 

the leak goes away is there something I am doing wrong?

I am testing in the Corona Simulator.

If you add this as the third line:

local txtTitle

Then change the line to:

txtTitle = display.newText("Test of memory leak",0,0,native.systemFont,32)

And finally (optionally?) add this line in scene:exitScene(e):

display.remove( txtTitle ) txtTitle = nil

Do you still get the memory leak?

Yes, still get the memory leak. Making those changes seems to have no affect.

Just for clarity

--\*\*\* --unchanged code --\*\*\* local txtTitle txtTitle = display.newText("Test of memory leak",0,0,native.systemFont,32\*\_ScaleFactorY) --... --unchanged code --... function scene:exitScene(e) display.remove(txtTitle) txtTitle = nil storyboard.purgeScene("moduleHome") print("Exit Home: "..system.getInfo( "textureMemoryUsed" )) end --\*\*\* --unchanged code --\*\*\*

You’re declaring local txtTitle outside of all the functions, yes?  Don’t place it inside the **scene:createScene() **function.

Ok that took care of it. Thanks.

Looks like I need to go back and read about storyboard and where the local variables to the scene need to go. I have been sticking all my local variables and local functions within scene:createScene()

If you add this as the third line:

local txtTitle

Then change the line to:

txtTitle = display.newText("Test of memory leak",0,0,native.systemFont,32)

And finally (optionally?) add this line in scene:exitScene(e):

display.remove( txtTitle ) txtTitle = nil

Do you still get the memory leak?

Yes, still get the memory leak. Making those changes seems to have no affect.

Just for clarity

--\*\*\* --unchanged code --\*\*\* local txtTitle txtTitle = display.newText("Test of memory leak",0,0,native.systemFont,32\*\_ScaleFactorY) --... --unchanged code --... function scene:exitScene(e) display.remove(txtTitle) txtTitle = nil storyboard.purgeScene("moduleHome") print("Exit Home: "..system.getInfo( "textureMemoryUsed" )) end --\*\*\* --unchanged code --\*\*\*

You’re declaring local txtTitle outside of all the functions, yes?  Don’t place it inside the **scene:createScene() **function.

Ok that took care of it. Thanks.

Looks like I need to go back and read about storyboard and where the local variables to the scene need to go. I have been sticking all my local variables and local functions within scene:createScene()