The iPhone has an extremely limited amount of RAM (especially for doing 3D work). During development of the latest 1.1.0 release of StarSmasher I ran up against the glass ceiling on the RAM quite a lot. StarSmasher was only using about 20 MB of RAM at peak levels but this was enough for the app to receive low memory warnings from the OS. I don’t load that many textures, but the menu screen textures where full resolution 512×512 jpegs and I wasn’t doing any kind of unloading when they weren’t being used. Ultimately, this caused the app to crash after a couple of levels. I had written it this way initially to make the app feel snappier (because I figured 20 megs wasn’t that bad) and because I’m learning OpenGL as I go and didn’t fully understand the texture management. 

Now I’ve implemented just in time texture loading for the menu screens that checks if the texture is loaded on draw and loads it if necessary. When a menu screen is exited (for instance by tapping the “done” button) I unload the texture (with glDeleteTextures). Below is the TextureLoader class I wrote to manage my textures.

Read the rest of this entry »

Posted on August 30th, 2008 | Filed under code::, iPhone dev | No Comments »