# Why does my FPS drop gradually over time?

I'm working on this game: yt alpha preview

I came into a huge game-breaking problem - after 10-15 min of gameplay the FPS drops from 60 to 30 and is very unstable. I'm using tons of physics and particles, I'm deleting and nulling everything I can after it's supposed to be removed, I remove objects from vectors etc. The memory usage is stable at around 150mb so a leak is unlikely (or invisible?)- after a round ends and I delete everything, play a new round and performance is still terrible. I spent two days trying to figure this out and I just can't fix it. Maybe I'm missing something? I know it's hard to help with no code but I would just have to post my whole source.

Flash garbage collector doesn't work very well, nor its destructors do a good job of actually destroying things either.

Even if your code is correct and shouldn't leak, Flash might mess it anyway.

Try to allocate the bare minimum of things you actually need, and instead of destorying and recreating them, just recycle them.

• unfortunately this is what i thought, thx for response. – mmankt Mar 21 '12 at 16:51
• i managed to fix it with a profiler, maybe someone else will have this problem: just make sure you have a destructor in your custom classes, delete and null everything you can – mmankt Apr 3 '12 at 19:19
• Good question and answer - you should mark this as the answer mmankt :) – Aralox Apr 3 '12 at 23:23
• Sounds to me like it wasn't actually the real answer (though a good one) – notlesh Apr 4 '12 at 3:05

I managed to fix it with a profiler (the miner). I had b2vec2 and sprite leaks.

GC won't gather if you keep references to objects so just make sure you have a destructor in your custom classes, delete and null everything you can. Most of all if you use big libraries such as box2d make sure you null even local vars. With bitmap data use bmpdat.dispose(); and null it. Thanks to this I'm using around 30-40mbs less and the game is stable and fluid for many rounds.

• Nice. I'm glad you found a solution. When you get a chance, mark this answer as correct. – John McDonald Apr 3 '12 at 20:38
• Keep in mind that on a GC-collected game, it's better to recycle objects if possible so that the garbage collection will never have to run, as Lohoris described. – doppelgreener Apr 4 '12 at 2:00