Thanks for the prompt response, as usual!
You too!
I was having trouble accessing the table keys/references for nilling out after the collision. (I’m only able to access the .name property of the collision object, and not its table key). Would you have any suggestions regarding that?
EDIT: I have discovered a way to nil all the keys of the spawn table onCollision, but I’m not sure if that’s the best approach.
Is there a more targeted way to approach this issue, say, only nilling the table key of an object after it has completed its collision (see issue above) ?
Also, I’ve tried using just a standard display group, and calling display.remove on the objects as they finish colliding with the barrier—that appears to work well too. I’m just concerned about the reduced flexibility of using standard display groups vs. the organizational benefits of tables, let me know if I’m missing out by only using groups. I’m still interested in solving my direct access to individual table keys onCollision issue though.
=====================================
This is what I have based on your suggestions:
local W = display.contentWidth local H = display.contentHeight local physics = require("physics") physics.start() physics.setDrawMode( "hybrid" ) local circles = {} local circleGroup = display.newGroup() local onCollision local removeThreshold = display.newRect(0, H\*0.5, W, 50) physics.addBody( removeThreshold, { density = 10, friction = 0.5, bounce = 0 } ) removeThreshold.bodyType = "static" removeThreshold.isSensor = true removeThreshold.name = "threshold" removeThreshold.collision = onCollision removeThreshold:addEventListener( "collision", removeThreshold ) circleGroup:insert(removeThreshold) local function spawnCircle() local circle = display.newCircle( 100, 100, 30 ) circle:setFillColor(128,128,128) circle.x = math.random(0, W) circle.name = "circle" circle.collision = onCollision circle:addEventListener( "collision", circle ) physics.addBody(circle, {density=50, bounce=0, radius=30}) circle.bodyType = "dynamic" circle.y = math.random(-100, -10) circle.index = #circles + 1 circleGroup:insert(circle) circle:setLinearVelocity(0, math.random(1000, 1000)) circles[circle.index] = circle return circle end function onCollision( self, event ) if ( event.phase == "began" ) then elseif ( event.phase == "ended" ) then self:removeSelf() self= nil for i=1, #circles do circles[i] = nil end end end local function cleanAll() physics.stop() for i=1, #circles do circles[i]:removeSelf() circles[i] = nil end display.remove(circleGroup) circleGroup = nil end local SpawnTimer = timer.performWithDelay(500, spawnCircle, 0) local removeTimer = timer.performWithDelay(20000, function()timer.cancel(SpawnTimer); spawnTimer=nil;cleanAll();end,1) local monitorMem = function() collectgarbage() local memCount = collectgarbage("count") / 1024 if (prevMemCount ~= memCount) then print( "MemUsage: " .. memCount .. "MB") prevMemCount = memCount end local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000 if (prevTextMem ~= textMem) then prevTextMem = textMem print( "TexMem: " .. textMem ) end end Runtime:addEventListener( "enterFrame", monitorMem )