I'm currently working on a very large Flash platformer game (hundreds of classes) and dealing with an issue where the game slowly grinds to a halt if you leave it on for long enough. I didn't write the game and so I'm only vaguely familiar with its internals. Some of the mysterious symptoms include,
- The game will run fine for a determinate amount of time (on a given level) when all of a sudden it will exponentially start leaking memory.
- The time it takes for the game to hit the point where it leaks exponentially is shorter when there's more sprites on the screen.
- Even when nothing is being visibly rendered to the screen, the game slows down.
- The game slows down faster with more frequent sprite collisions.
- Completely disabling the collision code does slow down the degradation but doesn't prevent the game from eventually dropping frames.
Looking at the source and using Flex profiler, my prime suspects are,
- There are many loitering objects, especially
WeakMethodClosure
, taking up large amounts of memory. - The program makes extremely extensive use of weak event listeners (dozens dispatched per frame).
- BitmapData is being copied every time a new sprite is created. These are 50x50 pixel sprites that spawn at about 8 sprites per second.
I know it's next to impossible to tell me the problem without seeing the source, so I'm just looking for tidbits that might help me narrow this down. Has anybody experienced this evasive performance degradation in their own projects? What was the cause in your case?