So I'm working on a puzzle game in flash. For all intents and purposes it's like Tetris. I spawn blocks, they move around the screen, then they get destroyed and disappear. I was having some trouble with the memory usage being too high over time so I read up on memory management and I think I have that figured out now. It's definitely climbing slower than it was before, but the framerate is still taking a huge dive after playing for a while. If it's not a memory leak what else could be causing this? Thanks in advance.
2 Answers
Either 2 of these it think:
- It would very well be that you are deleting stuff from the display-list but still have references in other places( like arrays ) that are still being processed. This keeps building up and completely hogs your game. ( but Flash can easily handle tons of objects )
or
-Your algorithm, even though simplistic, is flawed and is doing more work than necessary. Memory leaks are nearly impossible in AS3 unless you loose an object that holds a reference to an object you can't reach anymore ( like Events that aren't destroyed and never have their weak flag set to true).
This combined with the above one can really tear down the performance.
-
\$\begingroup\$ Hmm, at what amount of memory do you think the game could no longer handle 30 FPS? Because the game stays around 30 and no higher than 40. \$\endgroup\$ Commented Aug 8, 2012 at 2:44
-
\$\begingroup\$ It's not the amount of memory, rather the object your game needs to process. Keeping stuff in memory but not doing anything with them shouldn't directly affect the performance unless you do something with it. If your objects aren't rendering after removal, then you took them out of your display list. But you should also check if they are removed from arrays etc. The Garbage collector will only destroy the data if exactly 0 pointers are pointing to the data. \$\endgroup\$– SidarCommented Aug 8, 2012 at 2:48
-
\$\begingroup\$ I'm fairly sure I've taken care of this. Every time I destroy a block it looks like this: blockHolder.removeChild(block); delete(block); blocks.splice(blockIndex, 1); \$\endgroup\$ Commented Aug 8, 2012 at 2:59
-
\$\begingroup\$ Seems to be clean. What software are you using? Flashdevelop for example has a profiler which allows you to see various stats on object types, like the amount that are in memory. \$\endgroup\$– SidarCommented Aug 8, 2012 at 3:07
-
\$\begingroup\$ I'm just using Flash CS5 but I am currently using thMiner profiler but I don't really know what I'm doing with it or what I should be looking for. \$\endgroup\$ Commented Aug 8, 2012 at 3:13
http://gamedev.michaeljameswilliams.com/2009/03/25/avoider-game-tutorial-12/ you should visit this part of that tutorial, it will probably contain your problem, which is for example, not unloading the childs you create and instead just freeze them out of view. I could try to tell you details but check that out, at least you should get a lot of really useful tips.