Do I need to remove and nil every object when changing scene?

Hey guys, 

I have my gameplay scene, it has a lot going on in it, lots of animations and sprites all over the place, it works great at a steady 60 fps, when the game is over or level is complete I change to a different scene and I also use removeScene() on the gameplay scene just before switching to a different scene like so:

[lua]

function scene:didExitScene(e)

    storyboard.removeScene(“gameplay”)

end

[/lua]

If I do this, do I still need to remove every object from the scene?

meaning, Do I still need to do this for every object:

[lua]

object:removeSelf()

object = nil

[/lua]

Thanks in advanced.

Roy.

If your display objects have been inserted into a storyboard scene’s display group (group:insert(background) for instance), then no you do not need to dispose of them.  Storyboard will manage that for you.  However if you create something that’s not part of the scene’s group, or its a native.* object, you are responsible for destroying it yourself.

Thank again Rob!

My display objects are being inserted into storyboard so its all good!

Another question…

In lua, when I have a function , for example “foo” and inside this function I create a table, when the function ends, do I need to remove the table by hand? or will it be removed automatically from memory?

[lua]

function foo(  )

 dummyTable  = {   

    {1,4,4,2,4,6,6,5},

    {3,2,3,3,2,1,3,4},

    {2,3,1,4,4,5,3,5},

    {2,4,3,4,1,3,1,1},

    {3,6,3,1,6,1,3,4},

    {1,5,6,2,1,2,6,2},

    {6,2,2,4,2,5,2,4},

    {1,1,4,1,3,4,4,1},

    }

end

[/lua]

Roy.

A lot depends on where it’s at.  More importantly, if you are not adding data to it to grow the table, you really don’t need to worry about it.  It’s not a pool of memory that will grow over time and therefore you don’t need to worry about removing it.  Now if you’re adding to it and it will grow over time, you might want to take steps to reset it.  Simply nilling out an array like that will free up the memory.

Also, if it’s inside a function it will get created and destroyed with each invocation of the function.  It’s a lot like code in that respect.  If it’s in a module’s main chunk, it will persist until the module is un-required.  (storyboard.removeScene())

If your display objects have been inserted into a storyboard scene’s display group (group:insert(background) for instance), then no you do not need to dispose of them.  Storyboard will manage that for you.  However if you create something that’s not part of the scene’s group, or its a native.* object, you are responsible for destroying it yourself.

Thank again Rob!

My display objects are being inserted into storyboard so its all good!

Another question…

In lua, when I have a function , for example “foo” and inside this function I create a table, when the function ends, do I need to remove the table by hand? or will it be removed automatically from memory?

[lua]

function foo(  )

 dummyTable  = {   

    {1,4,4,2,4,6,6,5},

    {3,2,3,3,2,1,3,4},

    {2,3,1,4,4,5,3,5},

    {2,4,3,4,1,3,1,1},

    {3,6,3,1,6,1,3,4},

    {1,5,6,2,1,2,6,2},

    {6,2,2,4,2,5,2,4},

    {1,1,4,1,3,4,4,1},

    }

end

[/lua]

Roy.

A lot depends on where it’s at.  More importantly, if you are not adding data to it to grow the table, you really don’t need to worry about it.  It’s not a pool of memory that will grow over time and therefore you don’t need to worry about removing it.  Now if you’re adding to it and it will grow over time, you might want to take steps to reset it.  Simply nilling out an array like that will free up the memory.

Also, if it’s inside a function it will get created and destroyed with each invocation of the function.  It’s a lot like code in that respect.  If it’s in a module’s main chunk, it will persist until the module is un-required.  (storyboard.removeScene())