I think the issue is that you’re creating so many objects at once. I can’t explain why that’s the case, but if you space it out for even a milisecond between each object creation the leak disappears. Here’s the code I used:
local table = {}
local monitorMem = function()
collectgarbage()
print( "MemUsage: " .. collectgarbage("count") )
end
monitorMem()
timer.performWithDelay( 500, monitorMem, 0 )
local function makerects()
local myRect = display.newRect(100,100,10,50)
table[#table + 1] = myRect
for i, obj in pairs( table ) do
display.remove( myRect )
myRect = nil
table[i] = nil
end
end
timer.performWithDelay( 1, makerects, 5000 )
And the terminal readout I get:
MemUsage: 78.419921875
MemUsage: 79.3837890625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
MemUsage: 79.4072265625
Maybe someone else could explain why creating the objects all at once vs spacing them out causes the leak. Or maybe were both doing it wrong. [import]uid: 10903 topic_id: 20379 reply_id: 79702[/import]