Nested displayObjects and Groups with Event Listeners

Hi Guys,

             Can someone tell me if I remove the top most group, will it remove all the child groups, displayObjects and eventListeners inside of it?

I can’t find any new information on this but in the old days you used to have to manually remove any event listeners you added.

I’ve been doing testing though monitoring memory usage with the below function:

local monitorMem = function()

    collectgarbage()
    print( "\nMemUsage: " … collectgarbage(“count”) )

    local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
    print( "TexMem:   " … textMem )
end

Runtime:addEventListener( “enterFrame”, monitorMem )

and I can’t see a memory leak if I don’t remove the eventListeners… e.g If I keep removing the top group and re-creating it along with all the children the memory is not increasing like I would expect?

Can someone please confirm?

In my example, I have a display group called screen1, this contains a scrollView and inside the scroll view is another display group which holds a grid of squares, each square is a display group that contains 5 display objects, 1 of those display objects has an event listener.

Kind Regards,

Krivvenz.

Doh finally I think I found my answer in the following documentation:

https://docs.coronalabs.com/api/type/DisplayObject/removeSelf.html

removing the top group will kill everything contained in it as long as no other references to it remain.

You still need to remove any Runtime listeners yourself.

i.e. 

If you delete this object, the touch listener will go away automatically:

local obj = display.newCircle( 10, 10, 10 ) function obj.touch( self, event ) -- body of listener here end obj:addEventListener( "touch" ) -- ... then later display.remove( obj ) -- touch listener automatically removed

However, if did this, it would not work right:

local obj = display.newCircle( 10, 10, 10 ) -- accelerometer function obj.accelerometer( self, event ) -- body of listener here end Runtime:addEventListener( "accelerometer", obj ) -- ... then later display.remove( obj ) -- accelerometer listener NOT automatically removed

Doh finally I think I found my answer in the following documentation:

https://docs.coronalabs.com/api/type/DisplayObject/removeSelf.html

removing the top group will kill everything contained in it as long as no other references to it remain.

You still need to remove any Runtime listeners yourself.

i.e. 

If you delete this object, the touch listener will go away automatically:

local obj = display.newCircle( 10, 10, 10 ) function obj.touch( self, event ) -- body of listener here end obj:addEventListener( "touch" ) -- ... then later display.remove( obj ) -- touch listener automatically removed

However, if did this, it would not work right:

local obj = display.newCircle( 10, 10, 10 ) -- accelerometer function obj.accelerometer( self, event ) -- body of listener here end Runtime:addEventListener( "accelerometer", obj ) -- ... then later display.remove( obj ) -- accelerometer listener NOT automatically removed