performance tweaks

I have been working on a game for a little over two months and im almost ready to release:)

The problem is the frame rate seems to get progressively slower the more you play the game.
I have also noticed that the garbage does get collected but it never gets as low as it was before the level started…meaning that when i start the game the garbage is at about 500. when i play a game and lose i force garbage collection and it goes back down to about 500. As you keep playing the minimum garbage seems to pass 500 and keeps getting larger.
As the garbage gets larger the framerate starts slowing down. I played a 5 or 6 games in a row and the fps got down to an average of 10 fps.
I have scoured these forums and my code and i am removing all event listeners setting variables to nil and I have even optimized my code. It seems that no matter what i do I cant get the frame rate to stay at 30 fps

Is there anything else I should be looking for?

[import]uid: 27671 topic_id: 8868 reply_id: 308868[/import]

What Corona build are you using?

If you were using the previous stable build (268), there were A TON of bug fixes and memory-leak fixes in the release that just launched (484). [import]uid: 52430 topic_id: 8868 reply_id: 32410[/import]

Thanks Jonathan. I did download 484 but im using CPM and it was still referencing 268. i uninstalled 268 and installede 484 and changed the reference in cpm to point to the new directory.

I just built the app with 484 and will commence testing now.

Thanks again. [import]uid: 27671 topic_id: 8868 reply_id: 32436[/import]

Sounds like a case of memory leaking. The GC can only collect things that are properly released. [import]uid: 5712 topic_id: 8868 reply_id: 32439[/import]

I just tested the app built with 484 on a Droid Incredible and its much better but the frame rate still starts to drop after 4 or 5 games.

I did notice that the gabage is much lower than before. Now when i force garbage collection it drops to a little over 400 every time. [import]uid: 27671 topic_id: 8868 reply_id: 32440[/import]

I have cleaned up my code quite a bit and garbage count gets down to about 360 - 400 after each level but the game still seems to slow after a while.

this happens both on the Droid Incredible and the ipod touch
[import]uid: 27671 topic_id: 8868 reply_id: 32597[/import]

use director.lua? have u clean up the listener properly? [import]uid: 12088 topic_id: 8868 reply_id: 32605[/import]

Im not using director.lua. As far as I can tell i am removing all listeners. Is there a function in corona that will tell me which listeners are active?

[import]uid: 27671 topic_id: 8868 reply_id: 32607[/import]

How big is your project? Listeners attached to objects themselves should be automatically cleaned up when you call removeSelf(), Runtime listeners might linger if you don’t manually remove them.

If you’re using a good text editor (such as BBEdit or TextWrangler), you can do a search for Runtime:addEventListener to find where all your runtime listeners are. You can then make sure, one-by-one, if they are removed after each run.

Also, are you setting your variables to nil after calling removeSelf()? [import]uid: 52430 topic_id: 8868 reply_id: 32609[/import]

my main file is 3700 lines. I also have a levels file that is 3480 lines.

Im using TextWrangler and I have verified that I am setting all variables to nil after calling removeSelf and removing listeners.
[import]uid: 27671 topic_id: 8868 reply_id: 32616[/import]

I found a couple of images that i wasnt removlng or setting to nil. I corrected the issue and the performance has improved but there is still a leak.

I believe i may have a bug thats activating the ontilt listener when it should not be using the accelerometer. Getting late so ill debug more tomorrow night and post my findings. [import]uid: 27671 topic_id: 8868 reply_id: 32619[/import]

[code]
for i = displayGroup.numChildren,1,-1 do
local child = displayGroup[i]

if child._tableListeners ~= nil then
for k,v in pairs(child._tableListeners) do
child:removeEventListener(k, child )
end
end
if child.enterFrame ~= nil then
Runtime:removeEventListener( “enterFrame”, child )
end
end
[/code] [import]uid: 12088 topic_id: 8868 reply_id: 32622[/import]

@jonathanbeebe: not every Listeners attached to objects themselves is automatically cleaned up when you call removeSelf(). e.g. postCollision and enterFrame [import]uid: 12088 topic_id: 8868 reply_id: 32624[/import]

enterFrame’s aren’t attached to the object though, it’s attached to Runtime … event listeners attached to the object themselves, e.g.

object:addEventListener( …

should be removed when removeSelf() is called.

enterFrame listeners are always attached to Runtime, like so:

Runtime:addEventListener( “enterFrame”, …


@joshdobbs: Definitely look into the accelerometer events. That’ll bog things down if that’s really the issue, however, if you’re using the simulator to detect these leaks, then that’s probably not it since you can’t access the accelerometer unless you’re on device. [import]uid: 52430 topic_id: 8868 reply_id: 32626[/import]

ok. Im pretty sure its not the accelerometer.

I have gone through and double and triple checked to make sure im removing everything…setting everything to nil and even cancelling timers and setting them to nil.

I can play through about 4 or 5 levels now before i see any sign of the framerate slowing.

any other suggestions?

At this point I don’t know what else i can do. [import]uid: 27671 topic_id: 8868 reply_id: 32879[/import]

Nevermind :). I figured it out. i was adding too many background images on a couple of levels and thus they were not getting removed properly. game is nice and smooth now.

[import]uid: 27671 topic_id: 8868 reply_id: 32884[/import]

after some further testing it seems to run fine on the Droid Incredible and the Nexus one however it slows down a bit on the ipod touch(i’m guessing its a 3rd generation, i bought it april or may of 2010).

I have yet to test on iPhone and iPad.

[import]uid: 27671 topic_id: 8868 reply_id: 32887[/import]

after some further testing it seems to run fine on the Droid Incredible and the Nexus one however it slows down a bit on the ipod touch(i’m guessing its a 3rd generation, i bought it april or may of 2010).

I have yet to test on iPhone and iPad.

[import]uid: 27671 topic_id: 8868 reply_id: 32888[/import]

congrats on figuring out the problem!

No worries on iPhone/iPad… with Corona, if you have it optimized for Android, it’ll be smooth as silk on current iOS devices. [import]uid: 52430 topic_id: 8868 reply_id: 32896[/import]

Thanks Jonathan!

You are Right! the first time i ran it on the ipod it was sluggish but every build after that seems fine. a little slower that the Android phones i’ve tested on but not a show stopper.

[import]uid: 27671 topic_id: 8868 reply_id: 32897[/import]