[SOLVED] Group Remove Doubt

Hello Community, I was wondering about how to remove display objects from a group correctly, so here are two examples:

Removing each object separately

group:remove ( background )  
background = nil  
group:remove ( glassTube )  
glassTube = nil  
group:remove ( bigCheese )  
bigCheese = nil  
group:remove ( car )  
car = nil  
group:remove ( downFloor )  
downFloor = nil  
group:remove ( scoreWall )  
scoreWall = nil  
group:removeSelf ()  
group = nil  

Removing the entire group

group:removeSelf ()  
group = nil  

Those ways are the same, or removing each object separately is better?

Or can I do this?

group:removeSelf () background = nil glassTube = nil bigCheese = nil car = nil downFloor = nil scoreWall = nil group = nil [import]uid: 81091 topic_id: 18734 reply_id: 318734[/import]

Removing entire group should be enough I think. [import]uid: 12704 topic_id: 18734 reply_id: 72027[/import]

For extra good-measure, you can also nil’-out the local references ot the objects that you removed when you removed the parent group. Observe:

myGroup:insert( obj1 )myGroup:insert( obj2 )myGroup:removeSelf()print( obj1, obj2 )[/code]The print statement above will still read obj1 and obj2 as tables, so it's best to nil' those out after removing the group. Since they are locals, they shouldn't cause too much damage and should be auto-freed when the block is executed, but to be safe, I'd always nil'-out whatever you can. [import]uid: 52430 topic_id: 18734 reply_id: 72047[/import]

all are correct. but best practices is to nil out so that in case there is still a reference to the variable it doesn’t wreak havoc.

c
[import]uid: 24 topic_id: 18734 reply_id: 72061[/import]

Which option would you choose to obtain the best performance? [import]uid: 81091 topic_id: 18734 reply_id: 72269[/import]

The option jon provided + nil out the variables [import]uid: 84637 topic_id: 18734 reply_id: 72525[/import]

Removing the entire group and then nil every object from the group? [import]uid: 81091 topic_id: 18734 reply_id: 72533[/import]

You may get away with nilling out just the group after removing it. If you want to be extra safe nil every object. (again this is where tables come in handy) [import]uid: 84637 topic_id: 18734 reply_id: 72542[/import]

Depends what references (“table variables”) you’ve kept. If you’ve only tracked the group, then that’s the only thing you need to nil. [import]uid: 58849 topic_id: 18734 reply_id: 72543[/import]

Ok, thanks for your replies guys. [import]uid: 81091 topic_id: 18734 reply_id: 72571[/import]