Hi all,
I’m not sure why the following example code doesn’t free up all the timer memory. It starts at around 133kb, if you tap the screen it creates 10,000 timers. After they have run, they should be cleaned up. However after removing all the timers, it levels out at about 389kb.
Am I missing something?
– main.lua
[lua]local removeTimer = false
local timers = {}
Runtime:addEventListener(“touch”, function(e)
if(e.phase == “began”) then
print(“TIMERS CREATED”)
timers = {}
for i=1,10000 do
table.insert(timers, timer.performWithDelay(3000, function(e)
removeTimer = true
end, 1))
end
end
end)
Runtime:addEventListener(“enterFrame”, function(e)
if(removeTimer) then
print(“KILLED TIMERS”)
for i=1,#timers do
local aTimer = timers[i]
timer.cancel(aTimer)
timers[i] = nil
end
timers = nil
removeTimer = false
end
collectgarbage(“collect”)
print( "MemUsage: " … collectgarbage(“count”) )
end)[/lua]
Thanks,
Aaron [import]uid: 118390 topic_id: 33111 reply_id: 333111[/import]