Memory Management Progress
Today was a good day for memory management.
Yesterday, I read about some tools for memory management. Adobe has one, of course. And folks say it's quite good for this sort of thing. It's a full IDE, though, and it has typical Adobe pricing (e.g. $700).
Another tool I read about, TheMiner, is a homebrew memory profiler. I accidentally learned about it while reading about memory leaks on Flixel forums. As it turns out, it's a pretty comprehensive memory profiler, possibly on par with Adobe's. And what's more, it'll only set one back an easy-to-swallow $45.
So I decided to give that a shot this morning, and wow. Talk about handy! Within minutes, I had found a serious memory leak in the items screen. New objects in memory were being created 20-30 times each second as soon as an item was picked up, and would continue to bloat memory each second even after putting the item down again. That means that from the earliest game screen, skill selection, memory use started inflating.
Finding the actual leak took a few more hours. Once I did, however, the game was much more stable. A few extra objects still get created here and there, but it's like 1-3 per second, and only while dragging an object. Otherwise, it seems to stop inflating.
What's even better, TheMiner helped me spot a few functions that were being called way too many times. Some of them shouldn't have even been called in the first place. Tracking those down and bypassing/disabling them sped up performance even more.
And finally, since TheMiner does such a good job of reporting memory usage and framerate, it seemed silly to keep Flixel's built-in debugger turned on, as it adds all kinds of extra invisible sprites and text objects to the screen, which were now redundant.
When all was said and done, NEO Scavenger actually felt pretty snappy. Things seemed much smoother and faster. Framerates were back up into the 30-60 range, instead of 11-30. And memory use seemed to stay below 500MB.
That's looking pretty promising, so I'll give it some more testing Monday, and start looking into the next build upload. I'm still finding some bugs here and there that resulted from all the memory management stuff I've added, so I don't want to jump the gun and upload a broken build. But I think I'm getting close!
Anyway, it was a good day. It feels nice to have made solid strides after yesterday's slow progress.
Hope everyone has a good weekend, and see you Monday!