Do display groups need to be removed from memory?

Do display groups need to be removed from memory?

Right now I am creating several newImageRecs and adding them to a display group.

Later I removeSelf and nil the display objects. 

Does the display group need to be manually removed as well?

Thanks!

Gullie

There are several posts about this. Just look in the forum or in the blog.

https://coronalabs.com/blog/2012/07/03/properly-removing-objects-and-variables/

I have read that before but still don’t know exactly how a display group is treated.

Are the 2 lines of code below “—IS THIS NEEDED–” necessary to clear the memory? Or this that display group treated like a table and cleared when the function is abandoned?

local function makeit()

    

    local outcast = {} – forward declaration

    local outcastGroup = display.newGroup()

    local function create_and_abandon()

        for i = 1, 10 do

            outcast[i] = display.newImage( “image.png” )

            outcast[i].x, outcast[i].y = i*20 , i*20

            outcastGroup:insert( outcast[i] )

        end

    end

    create_and_abandon()

    – we can now remove the object

    for i = outcastGroup.numChildren, 1 , -1 do

        outcast[i]:removeSelf()

        outcast[i] = nil

    end

    --------IS THIS NEEDED-----------

    outcastGroup:removeSelf()

    outcastGroup = nil

    

end  

Hi @gullie667,

I recommend that you manually remove it.

Brent

There are several posts about this. Just look in the forum or in the blog.

https://coronalabs.com/blog/2012/07/03/properly-removing-objects-and-variables/

I have read that before but still don’t know exactly how a display group is treated.

Are the 2 lines of code below “—IS THIS NEEDED–” necessary to clear the memory? Or this that display group treated like a table and cleared when the function is abandoned?

local function makeit()

    

    local outcast = {} – forward declaration

    local outcastGroup = display.newGroup()

    local function create_and_abandon()

        for i = 1, 10 do

            outcast[i] = display.newImage( “image.png” )

            outcast[i].x, outcast[i].y = i*20 , i*20

            outcastGroup:insert( outcast[i] )

        end

    end

    create_and_abandon()

    – we can now remove the object

    for i = outcastGroup.numChildren, 1 , -1 do

        outcast[i]:removeSelf()

        outcast[i] = nil

    end

    --------IS THIS NEEDED-----------

    outcastGroup:removeSelf()

    outcastGroup = nil

    

end  

Hi @gullie667,

I recommend that you manually remove it.

Brent