Storyboard, memory management

Hi, in using storyboard for a game. Looking at exitScene when this is called. I’m removing all listeners that I have going, one being attached to a ball. Then remove all is called, but print (ball)  still shows memory in use (i think - very new to this) table: 0x1076a72c0

Do I have to nil all local variables to free memory up? I’m just conscious that memory leaks can be an issue so am trying to get my head around this before the code becomes too long and harder to work through…

function scene:exitScene( event )
    local group = self.view

gameListeners(“remove”)

    storyboard.removeAll ( )
        
    print (ball)
end
 

Thanks,

Mark

If you have not added the ball (I’m assuming it’s a display object) to the scene’s view (or sub-group of it) then it will persist in the display group hierarchy and not be released. The code fragment you should post is where you create the ball object.

Hi Horace, this is the where the ball is setup

– Called when the scene’s view does not exist:
function scene:createScene( event )
    local group = self.view

    – CREATE display objects and add them to ‘group’ here.

    ball = display.newImage(“images/ball.png”)
    ball.x = centerX
    ball.y = screenBottom-ball.height*1.7                           
    group:insert(ball)

Thanks

Mark
    

Am I right in assuming I need to nil this out then? Is there an easy way to handle nilling out variables or is this something that you just repeat with each one?

Thanks,

Mark

Storyboard.removeAll won’t remove the current scene. Table data that is part of local variables will hang around after a scene is purged, but if its removed that memory will be cleaned up too. But even if you don’t remove the scene, when you come back, no more memory will be used by these object tables. If a storyboard scene is purged or removed, the display object memory will be cleaned up if its part of the scene’s view/group. These tables are not considered leaks.

ok thanks Rob, so as long as I remove eventlistenters then the rest is handle automatically via Storyboard. Is that a correct assumption?

Thanks,

Mark

Any display object (image, rectangle, circle, sprite, etc.) that is added to the scene’s “view” (i.e. “group” or “sceneGroup” depending on the template you’re using) gets removed by the scene.  Event handlers on those objects (touch, tap) can’t be interacted with once they are off screen and they can’t be interacted with after they have been removed.  You don’t have to worry about those.

If you put something on the Runtime (think of the whole screen or the whole app) that are going to call functions in your module that may get removed, are the ones you need to clean up.

Ahh I see - thanks Rob, thats very helpful.

If you have not added the ball (I’m assuming it’s a display object) to the scene’s view (or sub-group of it) then it will persist in the display group hierarchy and not be released. The code fragment you should post is where you create the ball object.

Hi Horace, this is the where the ball is setup

– Called when the scene’s view does not exist:
function scene:createScene( event )
    local group = self.view

    – CREATE display objects and add them to ‘group’ here.

    ball = display.newImage(“images/ball.png”)
    ball.x = centerX
    ball.y = screenBottom-ball.height*1.7                           
    group:insert(ball)

Thanks

Mark
    

Am I right in assuming I need to nil this out then? Is there an easy way to handle nilling out variables or is this something that you just repeat with each one?

Thanks,

Mark

Storyboard.removeAll won’t remove the current scene. Table data that is part of local variables will hang around after a scene is purged, but if its removed that memory will be cleaned up too. But even if you don’t remove the scene, when you come back, no more memory will be used by these object tables. If a storyboard scene is purged or removed, the display object memory will be cleaned up if its part of the scene’s view/group. These tables are not considered leaks.

ok thanks Rob, so as long as I remove eventlistenters then the rest is handle automatically via Storyboard. Is that a correct assumption?

Thanks,

Mark

Any display object (image, rectangle, circle, sprite, etc.) that is added to the scene’s “view” (i.e. “group” or “sceneGroup” depending on the template you’re using) gets removed by the scene.  Event handlers on those objects (touch, tap) can’t be interacted with once they are off screen and they can’t be interacted with after they have been removed.  You don’t have to worry about those.

If you put something on the Runtime (think of the whole screen or the whole app) that are going to call functions in your module that may get removed, are the ones you need to clean up.

Ahh I see - thanks Rob, thats very helpful.