6
\$\begingroup\$

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.

\$\endgroup\$

2 Answers 2

14
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ unfortunately this is what i thought, thx for response. \$\endgroup\$
    – mmankt
    Commented Mar 21, 2012 at 16:51
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – mmankt
    Commented Apr 3, 2012 at 19:19
  • 1
    \$\begingroup\$ Good question and answer - you should mark this as the answer mmankt :) \$\endgroup\$
    – Aralox
    Commented Apr 3, 2012 at 23:23
  • \$\begingroup\$ Sounds to me like it wasn't actually the real answer (though a good one) \$\endgroup\$
    – notlesh
    Commented Apr 4, 2012 at 3:05
4
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Nice. I'm glad you found a solution. When you get a chance, mark this answer as correct. \$\endgroup\$ Commented Apr 3, 2012 at 20:38
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 4, 2012 at 2:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .