I am new to Corona and have noticed a small memory leak issue when I remove a group. The leak seems to persists when I remove each object belonging to the group and then remove the group itself. Every reference is also “nil”-ed in both cases. Of course there is the strong possibility that, as a novice, I am doing something wrong. Here is the code reproducing my problem. Does anyone have an idea of what is going on?
[code]
– main.lua
– MAIN LOOP FUNCTIONS
local getInfo
local wrapFunctionLeaky1
local wrapFunctionLeaky2
local function leacky1() – Execute first
for i = 1, 100 do
wrapFunctionLeaky1()
print (getInfo())
end
end
local function leacky2() – Execute second
for i = 1, 100 do
wrapFunctionLeaky2()
print (getInfo())
end
end
– wrapFunctionLeaky1()
function wrapFunctionLeaky1()
local line = display.newGroup()
local segment1 = display.newLine(100,100,200,200)
local segment2 = display.newLine(200,200,300,300)
local segment3 = display.newLine(300,300,400,400)
line:insert(segment1)
line:insert(segment2)
line:insert(segment3)
display.remove(line)
line = nil
end
– wrapFunctionLeaky2()
function wrapFunctionLeaky2()
local line = display.newGroup()
local segment1 = display.newLine(100,100,200,200)
local segment2 = display.newLine(200,200,300,300)
local segment3 = display.newLine(300,300,400,400)
line:insert(segment1)
line:insert(segment2)
line:insert(segment3)
display.remove(segment1)
segment1 = nil
display.remove(segment2)
segment2 = nil
display.remove(segment3)
segment3 = nil
display.remove(line)
line = nil
end
– getInfo()
function getInfo()
collectgarbage()
local memoryUsage = collectgarbage(“count”)
local textureMemoryUsage = system.getInfo(“textureMemoryUsed”)
return memoryUsage, textureMemoryUsage
end
– EXECUTE MAIN LOOP
leacky1()
print ("*** end leaky 1 ***")
leacky2()
print ("*** end leaky 2 ***")
[/code] [import]uid: 159908 topic_id: 30786 reply_id: 330786[/import]
on one hand you have just proven that removing a display group is exactly the same as removing each child and the group (which is what I originally wanted to test – in my project i am nesting display groups and I only remove only the parent when I destroy the scene; however I am noticing a memory leak each time I change “scene”). On the other hand calling functions repeatedly and quickly yields inexplicable memory consumption.