Hi there,
With this sample code, will there be a memory leak on the “bullet” variable, assuming the player taps the screen in rapid succession so that there are more than one “bullet” seen on screen at a given time?
\_W = display.contentWidth \_H = display.contentHeight physics = require("physics") physics:start() physics.setGravity(0,0) local barrier = display.newRect(0,10,\_W,15) barrier.x = \_W/2 physics.addBody(barrier, "static", {density=0.2, friction=0.2, bounce=0.2}) local bullet ------------------------------------------------- local function onBarrierCollision( self, event ) if event.other.name == "bullet" then event.other:removeSelf() event.other = nil print("bullet removed..." ) end end barrier.collision = onBarrierCollision barrier:addEventListener("collision", barrier ) ----------------------------- local function gunner(event) if event.phase == "began" then bullet = display.newCircle(\_W/2, \_H-50, 5) bullet.x = \_W/2 bullet.y = \_H-50 bullet.name = "bullet" physics.addBody(bullet, "dynamic", {density=1.5, bounce=0}) bullet:applyLinearImpulse(0, -2) end end Runtime:addEventListener( "touch", gunner )
Your comments will be highly appreciated.
Thanks!