why calling timer.cancel() does not release the memory right away?

For the following code, if I keep clicking on “Click Me”, I found Lua memory usage keeps increasing.

Later I conclude that timer.cancel() does not release memory right away but until the time out happens (in this case 25 seconds later)

Is this an on-purpose design or I have missed something?

local \_timerHandle local \_button = display.newText("Click Me", 0, 0, native.systemFontBold, 125 ) \_button.x = display.contentWidth\*0.5 \_button.y = display.contentHeight\*0.5 \_button:addEventListener( "tap", function() print("click me is clicked...") if (\_timerHandle ~= nil) then print("cancel previous timer...") timer.cancel(\_timerHandle) \_timerHandle = nil end \_timerHandle = timer.performWithDelay(25000, function() print("timer triggered...") end) end)

Garbage collection doesn’t happen instantly.  It happens periodically based on the speed and volume of memory that’s churning.  It could be 30 seconds or longer before it runs to reclaim the memory.

Rob

Garbage collection doesn’t happen instantly.  It happens periodically based on the speed and volume of memory that’s churning.  It could be 30 seconds or longer before it runs to reclaim the memory.

Rob