in Corona and Lua - how do I completely remove a display object (an image) from the screen and also from memory

jasonbb
jasonbb used Ask the Experts™
on
I am trying to fix my memory leak in Lua.
To test, I am creating 100,000 images on screen and recording them.
Then I remove them from the display. This works.
The problem is that the memory used never reduces back to that before the creation.
Here is my code:

local _storeContents = {}
local function OnDebugTest( event )
    for i = 1, 100000, 1 do
        img = display.newImage( "planet1.png", math.random()*400, math.random()*400-200 )
        _group:insert(img)
        table.insert(_storeContents,img)
    end

    for a,b in pairs(_storeContents) do
        display.remove(b)
    end

    _storeContents = {}
end

I am using gcinfo() to get the memory usage.
What do I need to do to fix the memory leak?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
jasonbbSoftware Engineer

Author

Commented:
I think the code is working and is releasing the memory.
I made this change to the code:
    for a,b in pairs(_storeContents) do
        display.remove(b)
        _storeContents [a] = nil
    end
and I use this later, called from a button:
    collectgarbage()

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial