Frame rate dropping after 15-20 minutes of play?

Hi,

I appreciate this may be a bit vague for anyone to answer but I was hoping someone might be able to point me in the right direction.

I’ve been putting together a game and all looked fine, I have a start screen, 3 levels and some choices for the player before getting to the levels. I gave it to my girlfriend to play and everything was running smoothly, she then asked me a question about something so I took a look at the screen and although she hadn’t noticed (!!) the frame rate had dropped considerably, it seemed to be missing a lot of frames.

I shut the game down and started it back up again and played on the 3 levels myself, I would sometimes fail a level and restart or complete a level and restart and flick between the levels until I could see the frame rate drop, there was no significant drop in the frame rate until after around 15-20 minutes of playing.

All my levels and screens are in different lua files so I can only assume I’m not releasing them from memory properly although I’m absolutely convinced I was releasing all my objects as I’m supposed to. Is this likely to be a problem with not releasing objects or should I be looking elsewhere?

I don’t really want to take wild guesses as to where I need to focus my energy otherwise I’ll end up spending 15-20 minutes each and every time I make some changes just to see if the frame rate is still dropping and that could get tedious very quickly!!

Any advice would be great…thanks. [import]uid: 107915 topic_id: 35330 reply_id: 335330[/import]

Would really suggest using a profiler. Either the excellent 3rd party app or I believe there is a free bit in the code share depository that might help (maybe _activate? I do remember there being something there…)

There’s all sorts of possible problems you could be running into but your first stop really be to just measure memory use and see what happens with that over time. [import]uid: 41884 topic_id: 35330 reply_id: 140433[/import]

Hey!

by what you have explained it seems to me that you have some memory leaks. Memory leaks are cause when you create something (such as a timer or variable) and you don"t properly get rid of it.
If you are at the scene A, it will show the memory usage, then if you go to scene B and the number might go up (if more things are going on then more memory will be used) and then if you go back to scene A and it goes up again then that means you have some leaking memory

check out this link for ways of finding and fixing memory leaks-
http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/
Hope all goes well,
-Boxie

You can check your memory usage by adding this code to your main.lua file-

[lua]local monitorMem = function()

collectgarbage()
print( "MemUsage: " … collectgarbage(“count”) )

local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
print( "TexMem: " … textMem )
end

Runtime:addEventListener( “enterFrame”, monitorMem )
[import]uid: 113909 topic_id: 35330 reply_id: 140434[/import]

Thanks both for your replies.

I had a feeling it would likely be with memory, looks like that is definitely going to be the obvious place to start. Now the difficulty will be trying to figure out what I’m not getting rid of…that should be fun! Teach me to be more careful in the future!!

Thanks again. [import]uid: 107915 topic_id: 35330 reply_id: 140451[/import]

Hi @chris460.

Do you use masks in your game? I have faced several fps issues when using masks.

Renato
Red Beach Games
Try our new game Puzzle You for free here!

[import]uid: 181011 topic_id: 35330 reply_id: 140517[/import]

One thing that could cause this is if you’re using enterFrame events, and you’re not removing them when changing scenes.

If that happens, a lot of extra processing can go on every screen frame. And if you bounce between activities, and various enterFrame listeners pile up in queue and get called multiple times on top of each other, it could cause frame loss. (it will call enterframe twice per frame if you add the listener twice, without removing the first…) [import]uid: 79933 topic_id: 35330 reply_id: 140522[/import]

@Renato - Thanks for the response. I am using scrollviews but no masks, I initially set up using a mask and then realised I didn’t actually need it.

@mpappas - It’s a good point about the enterFrame events, I’m convinced I am removing them on scene changes but there are times when I remove and add them again during a level so I think I’m going to take a closer look and add some print commands to ensure they are being removed during the level…thanks. [import]uid: 107915 topic_id: 35330 reply_id: 140526[/import]

Okay so I’ve checked all my Runtime (enterFrame) events and printed to the log each time I add a listener and each time I remove a listener and it seems they are getting added and removed at the correct times, there’s just one problem I can see although I’m not sure if it matters anyway.

I remove a Runtime (enterFrame) event (it’s movement of the camera) when a level is failed or completed and a couple of buttons show, either to replay the level or choose a level. If I tap on the choose level button the scene is dismissed and the Choose Level scene appears BUT I’m getting a print to the log of ‘Runtime Remove - Move Camera’ which is something I added to obviously tell when a runtime event is being removed, however I already removed this runtime listener when the level failed or completed, so in other words it’s called twice with no error in the console?

Would the console not output an error if a Runtime listener no longer exists and I try to remove it or doesn’t it care whether the listener is there or not? [import]uid: 107915 topic_id: 35330 reply_id: 140529[/import]

I *believe* all the removeEventListener calls throw a pcall lua error when you try and remove a listener that doesn’t exist. I know the standard object removeEventListeners do (found out through butterfinger coding on those), so I’d expect the runtime remove would as well.

You could put a print statement in the handlers just for a test run… They will totally spam the console with the same string (so you can’t tell if they are still going or not) unless you print os.time or something as well. If you see the time still incrementing when it shouldn’t, you’d know they are still firing…
[import]uid: 79933 topic_id: 35330 reply_id: 140531[/import]

I added a bunch of removeEventListeners on the Runtime event (around 15 all at once) and no error shown in the console, so I can only presume it doesn’t throw an error like a normal event listener.

I’m going to add the print statement in the handlers like you say, as I think this will be the only real way to tell if they are being removed correctly. [import]uid: 107915 topic_id: 35330 reply_id: 140548[/import]

Would really suggest using a profiler. Either the excellent 3rd party app or I believe there is a free bit in the code share depository that might help (maybe _activate? I do remember there being something there…)

There’s all sorts of possible problems you could be running into but your first stop really be to just measure memory use and see what happens with that over time. [import]uid: 41884 topic_id: 35330 reply_id: 140433[/import]

Hey!

by what you have explained it seems to me that you have some memory leaks. Memory leaks are cause when you create something (such as a timer or variable) and you don"t properly get rid of it.
If you are at the scene A, it will show the memory usage, then if you go to scene B and the number might go up (if more things are going on then more memory will be used) and then if you go back to scene A and it goes up again then that means you have some leaking memory

check out this link for ways of finding and fixing memory leaks-
http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/
Hope all goes well,
-Boxie

You can check your memory usage by adding this code to your main.lua file-

[lua]local monitorMem = function()

collectgarbage()
print( "MemUsage: " … collectgarbage(“count”) )

local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
print( "TexMem: " … textMem )
end

Runtime:addEventListener( “enterFrame”, monitorMem )
[import]uid: 113909 topic_id: 35330 reply_id: 140434[/import]

Thanks both for your replies.

I had a feeling it would likely be with memory, looks like that is definitely going to be the obvious place to start. Now the difficulty will be trying to figure out what I’m not getting rid of…that should be fun! Teach me to be more careful in the future!!

Thanks again. [import]uid: 107915 topic_id: 35330 reply_id: 140451[/import]

Hi @chris460.

Do you use masks in your game? I have faced several fps issues when using masks.

Renato
Red Beach Games
Try our new game Puzzle You for free here!

[import]uid: 181011 topic_id: 35330 reply_id: 140517[/import]

One thing that could cause this is if you’re using enterFrame events, and you’re not removing them when changing scenes.

If that happens, a lot of extra processing can go on every screen frame. And if you bounce between activities, and various enterFrame listeners pile up in queue and get called multiple times on top of each other, it could cause frame loss. (it will call enterframe twice per frame if you add the listener twice, without removing the first…) [import]uid: 79933 topic_id: 35330 reply_id: 140522[/import]

@Renato - Thanks for the response. I am using scrollviews but no masks, I initially set up using a mask and then realised I didn’t actually need it.

@mpappas - It’s a good point about the enterFrame events, I’m convinced I am removing them on scene changes but there are times when I remove and add them again during a level so I think I’m going to take a closer look and add some print commands to ensure they are being removed during the level…thanks. [import]uid: 107915 topic_id: 35330 reply_id: 140526[/import]

Okay so I’ve checked all my Runtime (enterFrame) events and printed to the log each time I add a listener and each time I remove a listener and it seems they are getting added and removed at the correct times, there’s just one problem I can see although I’m not sure if it matters anyway.

I remove a Runtime (enterFrame) event (it’s movement of the camera) when a level is failed or completed and a couple of buttons show, either to replay the level or choose a level. If I tap on the choose level button the scene is dismissed and the Choose Level scene appears BUT I’m getting a print to the log of ‘Runtime Remove - Move Camera’ which is something I added to obviously tell when a runtime event is being removed, however I already removed this runtime listener when the level failed or completed, so in other words it’s called twice with no error in the console?

Would the console not output an error if a Runtime listener no longer exists and I try to remove it or doesn’t it care whether the listener is there or not? [import]uid: 107915 topic_id: 35330 reply_id: 140529[/import]

I *believe* all the removeEventListener calls throw a pcall lua error when you try and remove a listener that doesn’t exist. I know the standard object removeEventListeners do (found out through butterfinger coding on those), so I’d expect the runtime remove would as well.

You could put a print statement in the handlers just for a test run… They will totally spam the console with the same string (so you can’t tell if they are still going or not) unless you print os.time or something as well. If you see the time still incrementing when it shouldn’t, you’d know they are still firing…
[import]uid: 79933 topic_id: 35330 reply_id: 140531[/import]

I added a bunch of removeEventListeners on the Runtime event (around 15 all at once) and no error shown in the console, so I can only presume it doesn’t throw an error like a normal event listener.

I’m going to add the print statement in the handlers like you say, as I think this will be the only real way to tell if they are being removed correctly. [import]uid: 107915 topic_id: 35330 reply_id: 140548[/import]