So I am currently experiencing a memory leak when restarting the level. I am canceling all transitions and removing the event listeners when the character runs into an obstacle and dies. So I’m sort of confused on what it could be. Has anyone else experienced something like this? I am willing to post the code to the playGame class, but it is slightly just over 1000 lines of code. Just as a fair warning.
The texture memory purges just fine and constantly goes back down to its original number the level started with, but the physical memory keeps increasing by .10 every time I restart and keeps going up. It doesn’t stop at a certain number either.
Here is the gameOver lua code when I press a button within the scene.
local function onButtonRelease(event) local go = event.target.id if go == "quit" then composer.hideOverlay() composer.gotoScene("bgMain") music.mmSound() elseif go =="levelSel" then composer.hideOverlay() composer.gotoScene("bgLevel") music.mmSound() elseif go =="retry" then composer.hideOverlay() --composer.removeScene("playGame") composer.gotoScene("retry") end end
Here is the retry class. This class is actually an empty lua class that I just use as a transition between the playGame and gameOver.
function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). local getPrev = composer.getPrevious() if getPrev ~= nil then composer.removeScene(getPrev) end collectgarbage("collect") elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. local function goTo() composer.gotoScene("playGame") end timer.performWithDelay(500, goTo) end end
Here is the code for when the character runs into an obsatcle and dies.
function collision(self, event) if event.phase == "began" then --Collision with asteroids if self.type == "player" and event.other.type == "obstacle" then local function trans() --Removes images to and transition into gameOver Text:removeSelf() Text = nil pause:removeSelf() pause = nil scoreText:removeSelf() scoreText = nil gemCounter:removeSelf() gemCounter = nil coinCounter:removeSelf() coinCounter = nil coinFont:removeSelf() coinFont = nil gem:pause() transition.cancel() timer:destroyTimer(pick) timer:destroyTimer(genGems) timer:destroyTimer(tapAnalog) char:remove() charDies:remove() composer.showOverlay("gameOver") end highsaveScore() if char:currentAnimation() == "back" or char:currentAnimation() == "up" or char:currentAnimation() == "down" or char:currentAnimation() == "forward" or char:currentAnimation() == "idle" then Runtime:removeEventListener("enterFrame", move) Runtime:removeEventListener("enterFrame", move2) Runtime:removeEventListener("enterFrame", move3) Runtime:removeEventListener( "enterFrame", main ) Runtime:removeEventListener("touch", moveAnalog) char:removeEventListener("collision", char) transition.cancel("transTag") timer:pauseAllTimers() music.remove() charDies:newAnim("dead", mcx.sequence({name = "playerSel/characters/player/gameOverAnim/dies", extension = "png", endFrame = 24, zeros = 2}), 351, 330, {speed = 1, loops = 1}) char:stop() charDies:play({name = "dead"}) transition.to(charDies, {delay = 1000, onComplete = trans}) end -- Collision with gems elseif self.type == "player" and event.other.type == "gems1" or event.other.type == "gems2" then score.add(event.other.value) event.other.alpha = 0 --Makes the type not equal so the collision is not dected this is to keep the collision at 1 if event.other.type =="gems1" or event.other.type == "gems2" then event.other.type = "none" end end end end
Any ideas? Like I said earlier, I’m willing to post the entire code. Thanks for reading! I appreciate it.