I recently purchased Torque 2D for the iPhone and came across a large memory leak in their iTGB 1.2 release whenever I ran the game on my iPhone 3G. I had a very basic platform game running with no engine modifications to the source code at all. The game would run for about 4 minutes before running out of memory and exiting. If I opened Organizer in Xcode and looked at the Console tab I’d see this:
Tue Aug 25 21:52:15 unknown SpringBoard[23] : Memory level is urgent (9%) and there are no background apps to ask to exit.
Tue Aug 25 21:53:18 unknown SpringBoard[23] : Application ‘MyGame’ exited abnormally with signal 11: Segmentation fault
Tue Aug 25 21:53:19 unknown ReportCrash[4565] : Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2009-08-25-215318.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
As I was a complete noob to the engine, I assumed I’d done something wrong. I checked my scripts and made sure I wasn’t allocating memory anywhere and that I wasn’t doing anything silly like executing scripts within a loop. Eventually I ran out of ideas and reverted to iTGB 1.1, which didn’t suffer from the memory leak.
I decided I’d rather use the latest and greatest offering so I thought I’d revisit iTGB 1.2. I recompiled TGEGame with PUAP_OPTIMIZE and PUAP_SCRIPT_CHANGE so the options set are now
__MACOSX__ TORQUE_DISABLE_MEMORY_MANAGER TORQUE_PLAYER TORQUE_RELEASE PUAP_SCRIPT_CHANGE PUAP_OPTIMIZE USE_COMPONENTS
I *may* have added the ‘R’ on to the end of TORQUE_DISABLE_MEMORY_MANAGER. There was a typo in some of the projects. Mostly on release configs but I can’t remember which ones.
Then I opened the Xcode_iPhone project and switched to the iTGB_Script_Optimize target. In release build I made sure these were set:
__IPHONE__ TORQUE_DISABLE_MEMORY_MANAGER TORQUE_PLAYER TORQUE_RELEASE PUAP_SCRIPT_CHANGE PUAP_OPTIMIZE USE_COMPONENTS
I’m pretty sure I added the ‘R’ on the end of TORQUE_DISABLE_MEMORY_MANAGER this time.
Then I made sure Compiler Version was set to GCC 4.0 and under Linking I changed C++ Standard Library Type from Static to Dynamic.
I also set my iPhone OS Deployment Target and Base SDK to iPhone OS 3.0. You probably don’t need to do that but I’m mentioning it anyway. If you’re having trouble compiling for 3.01 even though you have the latest non-beta iPhone SDK then you may need to create a symbolic link from your Terminal / shell.
cd /Developer/Platforms/iPhoneOS.platform/DeviceSupport ln -s 3.0 3.0.1
I don’t have the big memory leak any more
Comments