I have a problem that only seems to have shown up since I upgraded to the release build of 2.0. The game I am working on seems to have developed a strange resource leak. The game runs fine for a few minutes, then starts to bog down, and eventually the frame rate hits single digits. The problem is worse in the standalone player, but it shows up in the browser, too.
My first thought was that I had actors not being properly disposed of. So, I wrote a behavior to display every single actor type and a running count of how many of each actor exist in the current scene. That does not seem to be the problem, all created actors are being destroyed, and the numbers all fall back to zero as actors leave the screen/are destroyed by bullets/whatever.
Next, I conjectured that I had an out-of-control behavior doing something silly, so I wrote a profiling behavior and timed every single behavior being used in my game. Although I do have a few resource hogs, they are all fairly stable. I don't have any behaviors that expand to gobble up more and more cycles as they run. So, that also doesn't explain the creeping slowdown.
My actors are being properly disposed of, and my behaviors are crunching along at a steady pace, but my game keeps slowing down, anyway. It _seems_ to be centered around creating and destroying actors. I say _seems_ because I really haven't been able to pinpoint the problem, but I can sort of coax it into happening by creating and destroying a ton of actors. It isn't the actual creating and destroying that eats up the time, though. The slowdown continues even after the actors have been created or disposed of. The game behaves as if there are many actors in play, even when the actual count shows few or none.
Here's an illustration of the problem:
I have a character that produces a burst of bullets. The frame rate takes a hit when the bullets are created, but jumps right back to 60 FPS as soon as the creation is complete. The bullets go zipping off the screen and are destroyed. After a few dozen bursts, I notice that the frame rate is taking more of a hit, and not recovering as quickly. Instead of dropping to 50 FPS when the bullets are created, it drops into the 30s, and takes a couple of seconds to get back to 50+. Then, after a few dozen more bursts, the frame rate drops all the way to single digits every time there is a burst, and takes a long time to recover, and never actually recovers all the way to FPS, instead hitting the 20s or 30s. Essentially, the game is acting like I have dozens and dozens of actors in play, even though the actual count is zero once the bullets fly off and are destroyed. It's as if every time I created an actor of type "Bullet," every "Bullet" that I ever created (and destroyed) is being processed. The "Update" and "Render" times jump through the roof when the new burst is created, then settle down some once the bullets fly off the screen. This gets worse and worse as the game plays on. At the beginning, the increase in Update and Render time is not even noticeable.
I have a game uploaded under my account with "Trimmed" in the name. I don't want to make it public, but the Stencyl team are welcome to look at it. It's not perfect, but it's the easiest way I could fine to demonstrate the issue. The problem is actually worse in a "real" game, where multiple types of actor are being created and destroyed, and multiple actors are shooting bullets at one another. It works like this: Load the game, and hold your Shift key down right from the beginning. Holding Shift shuts off the bullet firing behavior. While holding Shift, hit the tilde and look at the Update, Flixel, and Render times. On my computer, they are something like 0ms Update, 6ms Render, 6ms Flixel, 8ms Flash, 14ms total, 60FPS. Let go of the Shift key and let the ship spew bullets for a few minutes. Now, hit Shift, again, and notice that Update, Render, etc, stay much higher than before and the FPS drops (on my computer) by a solid 10+ FPS. Repeat the process, and watch how Update, Render, etc, creep even higher, as the framerate bogs down. The yellow text on the left shows a running count of all actors in the game. You'll notice the performance degrades despite the number of actors settling back to 0 every time. I've tried this on three different PCs with completely different hardware (probably different versions of the Flash player, too, but I didn't check) and they all show the same problem. I did not notice this happening pre-2.0.
As I mentioned, it takes longer for the effect to show up in the browser (Firefox, for me), so leave the game sit a few minutes if you want to see what I'm talking about.