I have a gameloop function which initiates enemy creation, and a collision event where I destroy the enemy object… but every time I remove the object inside a collision I got memory leak… instead of memory going down then up (cause after I remove, it also triggers the gameloop to produce another enemy when existing enemy is destroyed)… it goes up and up and up… help needed guys…
[code]
–>>heres the collision event…
local function onCollision(self, event )
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
--\> 1st Enemy Object Colision with Ball
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
if self.name == "enemy" and event.other.name == "ball" and event.phase == "began" then
enemy:removeSelf()
enemy = nil
function removeEnemy()
enemy1IsPresent = 0
initGameLoop()
end
explodeAnim = display.newImageRect("poof-f1.png" , 100, 100 )
explodeAnim.x = self.x
explodeAnim.y = self.y
transition.to( poofAnim, { time=1000, alpha = .50,onComplete =function() poofAnim:removeSelf() poofAnim = nil removeEnemy() end} )
enemiesLayer:insert(poofAnim)
--\>\>heres my gameloop code...
function gameLoop()
if gameIsActive then
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
--\> 1st Enemy Create()
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
if enemy1IsPresent == 0 then
enemy = movieclip.newAnim({ "goblin1.png","goblin1.png","goblin1.png","goblin1.png","goblin1.png","goblin1.png","goblin1.png","goblin1.png","goblin1.png", "goblin1h.png","goblin1h.png","goblin1h.png","goblin1h.png","goblin1h.png","goblin1h.png", "goblin1h.png","goblin1h.png","goblin1h.png" }, 85, 85 )
physics.addBody(enemy, "dynamic", {radius = 40, filter = {categoryBits = 2, maskBits = 1}})
enemy.name = "enemy"
enemiesLayer:insert(enemy)
enemy.x = math.random(50, display.contentWidth - 50)
enemy.y = math.random(0,100)
enemy:play{ startFrame=1, endFrame=18, loop=-1,remove=true }
enemy.collision = onCollision
enemy:addEventListener("collision", enemy)
enemy1IsPresent = 1
end
end
end
I was wondering what causes the leak… Any help would be greatly appreciated. Thanks [import]uid: 76899 topic_id: 14742 reply_id: 314742[/import]