Unity is a fantastic platform but those of us that have used it extensively know it has it’s quirks. Some of these quirks are related to memory management. Memory management is a big deal on mobile devices. They don’t have a lot of memory to start with and usually have constrained processing power as well.
On the iPhone it get’s even more complicated. The device doesn’t let you claim memory away from other applications. So often a user might have opened a number of other games or applications and they could have been irresponsible in their memory usage. You could just be out of luck and your application will crash if it requires too many resources. Recent updates to the iOS are better at this, but if you are developing a game you have to be aware of all the legacy phones that your game might end up on.
With the base developer platfomer from Unity you don’t have access to the code base, so you basically have to get your memory when the platform wants to give it to you.
While developing Hercules: Curse of the Hydra we ran into one particular memory issue that drove us pretty batty for a while. We would find that while playing game levels memory would accumulate and the game would crash out. We’d comb over a level and try to figure out what the heck was going on. The levels weren’t larger than others and they had the same texture requirements. What was going on?
The answer came when we looked at the order of the levels as scenes. If you played the level first off it had no problems. If you played it in succession big trouble. Unity was not releasing memory between scenes. It would accumulate form scene to scene and cause the the application to crash out. We tried all the code calls that were supposed to release memory to no effect.
Hmm, so if memory was accumulating between scenes then how many scenes were held in memory. Through experimentation it seemed like it was just one. So the solution in the end was to insert empty scenes between the content scenes. This seemed to effectively dump the memory and allow us to keep Hercules slashing and hacking.
Ta da. Problem solved. If you’re a Unity developer we hope this little tidbit helps you out. Soon you’ll be able to download Hercules and see it in action!