Curious about memory leaks. Initially, I was planning on asking why the below code (without the 2 commented out line) leaked. I’ve read about forward declaration and setting things to nil, but I just can’t wrap my head around why I’d have to set the local square to nil since it falls out of scope, thus removing any reference from my own code, and I was hoping display.remove(group) would take care of the rest.
However, what I noticed is that even with those 2 lines commented out, there appears to be a small leak. It’s not a typical leak though - it doesn’t keep growing. So I assume it’s just something fundamental I don’t understand, but what??
local storyboard = require('storyboard') storyboard.isDebug = true local group local function toggle() if group ~= nil then display.remove(group) group = nil else group = display.newGroup() for i = 1, 5 do -- local square = display.newRect(group, i \* 50, 50, 25, 25) -- square:setFillColor(0,0,0.5,1) end end end Runtime:addEventListener('tap', toggle) local function stats() collectgarbage() storyboard.printMemUsage() timer.performWithDelay(1000, stats) end stats()