In the first code sample, I notice you’ve put the “player” into the group, but you’ve also placed listeners on the player object (“touch” and “collision”). Where do you remove those listeners? Somewhere else in the code that you didn’t include?
In the second code sample, that’s a reasonable approach, except that in your example, you’re adding the player as a dictionary item in the table (named “player”), and then when you clear you’re attempting to loop through by index numbers. It will not clear the items that way.
So, you’d have to change it one of two ways:
[lua]
myTable[#myTable+1] = display.newSprite …
for j = #myTable,1,-1 do --REVERSE ORDER!!!
display.remove(myTable[j])
myTable[j] = nil
end
[/lua]
—OR—
[lua]
myTable.player = display.newSprite …
for p,v in pairs( myTable ) do
display.remove( myTable[p] )
myTable[p] = nil
end
[/lua]