Best way to remove all objects loaded into a table?

I was looking at the “Multitouch” sample, and I see that it creates objects and stores them into a table location. In the example, it shows how to remove the objects as they leave the screen area.

What I was wondering is if I change scenes using a storyboard API, what would be the best way to remove all objects on the screen and off the screen? Just remove all objects created with the spawnDisk function global?

Do I need to create a For Loop and remove all objects in the table individually or is there a simpler way to dump the whole table, and all objects within the table?

Below is the sample code from Multitouch for reference.

[code]
local function spawnDisk( event )
local phase = event.phase

if “ended” == phase then
audio.play( popSound )
myLabel.isVisible = false

randImage = diskGfx[math.random( 1, 3 )]
allDisks[#allDisks + 1] = display.newImage( randImage )
local disk = allDisks[#allDisks]
disk.x = event.x; disk.y = event.y
disk.rotation = math.random( 1, 360 )
disk.xScale = 0.8; disk.yScale = 0.8

transition.to(disk, { time = 500, xScale = 1.0, yScale = 1.0, transition = easingx.easeOutElastic }) – “pop” animation

physics.addBody( disk, { density=0.3, friction=0.6, radius=66.0 } )
disk.linearDamping = 0.4
disk.angularDamping = 0.6

disk:addEventListener( “touch”, dragBody ) – make object draggable
end

return true
end
[/code] [import]uid: 152474 topic_id: 29211 reply_id: 329211[/import]

With Storyboard, you typically add every added display object into the scene’s view using the displayGroup called “group”.

When the scene is disposed of, Storyboard will remove the group and as such remove all of its children objects.

The only things you have to worry about removing manually are any objects that you don’t put into group (things that sit above the storyboard, like HUD items and you typically don’t create those as part of a storyboard scene), any timers or Runtime event listeners that you create. You are also responsible to stopping any thing that’s going to generate a call back, like using onComplete with audio.play() that will try to call a function that’s been removed.
[import]uid: 19626 topic_id: 29211 reply_id: 117518[/import]

@robmiracle

Thank you. I added the screen group and Storyboard took care of cleaning up all the spawned images.

[code]
local function spawnPopCorn( event )
local phase = event.phase

if “ended” == phase then
audio.play( popSound )

randImage = popcornRandom[math.random( 1, 3 )]
popcornAll[#popcornAll+1] = display.newImage( randImage )
popcorn = popcornAll[#popcornAll]
popcorn.x = event.x; popcorn.y = event.y
popcorn.rotation = math.random( 1, 360 )
popcorn.xScale = 0.8; popcorn.yScale = 0.8

screenGroup:insert( popcorn)
transition.to(popcorn, { time = 500, xScale = 1.0, yScale = 1.0, transition = easingx.easeOutElastic })

physics.addBody( popcorn, { density=0.3, friction=0.6, radius=20 } )
popcorn.linearDamping = 0.4
popcorn.angularDamping = 0.6

popcorn:addEventListener( “touch”, dragBody )
end
return true
end
[/code] [import]uid: 152474 topic_id: 29211 reply_id: 117642[/import]