DisplayObjects, Groups and Memory Management in Corona

Hello everybody,

I am wondering for a while about what really happens in terms of memory when I remove and set to nil groups and display objects.

I will use some examples to clarify my questions:

Case 1:

local myGroup = display.newGroup() local rect = display.newRect(0,0,100,100) myGroup:insert(rect) myGroup:removeSelf() myGroup:nil

Does removing and setting to nil ALSO frees from memory the rectangle or do I need to set rect to nil before removing the group?

Case 2:

local rect = display.newRect(0,0,100,100) rect.myProperty = "myProperty" rect:removeSelf() rect:nil

Does removing my rect ALSO frees from memory rect.myProperty? If yes, is this behaviour valid even if I add a table as a property (and all its elements, wich could also have some custom properties)?

Case 3:

local myGroup = display.newGroup() local rect = display.newRect(0,0,100,100) rect.myProperty = "myProperty" myGroup:insert(rect) myGroup:removeSelf() myGroup:nil

Am I freeing from memory the rectangle AND its custom property myProperty?

Briefly, can anyone give me a solid answer on how to prevent memory leaks in my Corona projects? Reading the Corona Guides didn’t help me, the more I read, the more I get confused!

I would also appreciate some common practice to manage memory in a clean way!

Thank you in advance!