Memory leak, or something else?

The FPS for my game seems to decrease incrementally after I exit my game level, return to the main menu, and start a new game.

I had assumed it was a memory leak, but the texture memory stays constant at 16.9mb and LUA’s garbage collection count seems to hold steady no matter how fast or slow the game is performing.

I’ve also tried not loading sound assets anymore, but the game still slows down. I’m making sure to remove all display objects when the level ends, setting the references to nil, removing all timers, removing the scene, and purging the scene.

What else can I do at this point to see what the problem is?

Can you post your code? This happened to me at first and it turned out to be a problem with how I was removing my runtime listener in the game scene. I had to ensure I removed it within the createscene or the enterscene event.

Basically it boils down to this:

local function gameLoop(event)     scene.player:update() end function scene:enterScene( event )     scene.player = require("playerObject");     physics.start()    scene.loopTimer = timer.performWithDelay(1/30, gameLoop, -1) end function scene:exitScene( event )     scene.player:destroy()     timer.cancel( scene.loopTimer )     physics.stop() storyboard.removeScene( "chicagoLevel" )     storyboard.purgeScene( "chicagoLevel" ) end function scene:destroyScene( event )     local group = self.view     group:removeSelf()              package.loaded[physics] = nil     physics = nil     scene = nil end  

Hopefully that helps.

I think you’re running into the same problem I was having with removing Runtime listeners. I’d suggest taking out the “scene.” handlers for your functions, forward declare your timer/Runtime function, and within the same timer/Runtime function, create a listener handle that cancels the timer or removes the Runtime listener. Here’s the thread I was commenting on that seemed to have the issue resolved:

http://forums.coronalabs.com/topic/29925-runtimeremoveeventlistener-messes-up-the-game/

timer.performWithDelay uses a millisecond value.  You’re telling your timer to fire 30 times per millisecond.  Try this (1/30)*1000 and see if things get better.  Also, 0 is the code for loop for ever, not -1.  See:
 

http://docs.coronalabs.com/api/library/timer/performWithDelay.html

Rob

I did change the value (and used 0 instead of -1), but it didn’t solve the problem. The frame rate just gets slower and slower as the game goes on. I didn’t think the timer was the issue anyway, since I’ve tried substituting that with the onEnterFrame event as well. 

The results are the same. The game slows to a crawl over time. (But only when going to the menu scene and coming back multiple times)

But did you change the first number from 1/30 to 333?  The first number is in milliseconds not seconds.

I changed it to (1/30)*1000, or 33.3, which is about equal to 30fps.

At this point now I’ve removed the timer entirely and am using the onEnterFrame event. I’m also printing out the time in the current frame vs time in the previous frame. Within the scene, the delta is the same. Every time I purge the scene, remove it, and then load it again, the delta in the time between frames gets higher while the texture memory and LUA garbage collection count remain the same.

Is your print statement still running after you exit the scene? If so, then you need to explicitly remove the Runtime listener, within the actual Runtime function itself.

No, the prints are stopping when I remove the onEnterFrame listener on the exitScene function and transition into the menu scene. They return when I load the game level scene from the menu.

It must be something taking place in your player:update() class. Can you provide that code?

Can you post your code? This happened to me at first and it turned out to be a problem with how I was removing my runtime listener in the game scene. I had to ensure I removed it within the createscene or the enterscene event.

Basically it boils down to this:

local function gameLoop(event)     scene.player:update() end function scene:enterScene( event )     scene.player = require("playerObject");     physics.start()    scene.loopTimer = timer.performWithDelay(1/30, gameLoop, -1) end function scene:exitScene( event )     scene.player:destroy()     timer.cancel( scene.loopTimer )     physics.stop() storyboard.removeScene( "chicagoLevel" )     storyboard.purgeScene( "chicagoLevel" ) end function scene:destroyScene( event )     local group = self.view     group:removeSelf()              package.loaded[physics] = nil     physics = nil     scene = nil end  

Hopefully that helps.

I think you’re running into the same problem I was having with removing Runtime listeners. I’d suggest taking out the “scene.” handlers for your functions, forward declare your timer/Runtime function, and within the same timer/Runtime function, create a listener handle that cancels the timer or removes the Runtime listener. Here’s the thread I was commenting on that seemed to have the issue resolved:

http://forums.coronalabs.com/topic/29925-runtimeremoveeventlistener-messes-up-the-game/

timer.performWithDelay uses a millisecond value.  You’re telling your timer to fire 30 times per millisecond.  Try this (1/30)*1000 and see if things get better.  Also, 0 is the code for loop for ever, not -1.  See:
 

http://docs.coronalabs.com/api/library/timer/performWithDelay.html

Rob

I did change the value (and used 0 instead of -1), but it didn’t solve the problem. The frame rate just gets slower and slower as the game goes on. I didn’t think the timer was the issue anyway, since I’ve tried substituting that with the onEnterFrame event as well. 

The results are the same. The game slows to a crawl over time. (But only when going to the menu scene and coming back multiple times)

But did you change the first number from 1/30 to 333?  The first number is in milliseconds not seconds.

I changed it to (1/30)*1000, or 33.3, which is about equal to 30fps.

At this point now I’ve removed the timer entirely and am using the onEnterFrame event. I’m also printing out the time in the current frame vs time in the previous frame. Within the scene, the delta is the same. Every time I purge the scene, remove it, and then load it again, the delta in the time between frames gets higher while the texture memory and LUA garbage collection count remain the same.

Is your print statement still running after you exit the scene? If so, then you need to explicitly remove the Runtime listener, within the actual Runtime function itself.

No, the prints are stopping when I remove the onEnterFrame listener on the exitScene function and transition into the menu scene. They return when I load the game level scene from the menu.