Skip Navigation

Ramblings from the team at zinc Roe

Metal Fish Eggs

How to check iPhone texture memory usage with Instruments

When developing iPhone games, one of the biggest performance optimizations you can make is to use OpenGL ES for rendering (instead of CoreGraphics or UIKit). For a 2D game like Arctic Shuffle, this means loading all of the animation into Open GL as textures, and drawing them onto simple rectangular shapes.

There are two caveats to this approach. First, disk access on the device is dirt slow, so you can forget about loading textures on the fly – all of the textures need to be loaded before gameplay begins. Second, OpenGL ES on the iPhone has a texture memory limit of 24MB. If you try to load more than 24MB of textures (including any buffers, like the framebuffer), the device has to start swapping them in and out of memory, and you go over a performance cliff, so to speak.

With that in mind, it’s very helpful to know how much texture memory is being used by your game – this is where Instruments comes in (the instructions below assume that your device is plugged into your development machine and you already have a working debug build of your game on the device).

1. Open Instruments (/Developer/Applications/Instruments.app) and choose the “Blank” template.

Step 1

2. In the bottom-left corner of instruments, click on the gear icon, then choose Add Instrument > Memory Monitory. Click the gear icon again and choose Add Instrument > OpenGL ES.

Step 2

3. Click on the OpenGL ES instrument’s info icon, and make sure that GARTResident Object Size is checked.

Step 3

4. Choose the device and application you wan to check. My device is named Barracuda and the application is ArcticShuffle2.

Step 4

5. Click the record button. This will launch the application on the device, and start monitoring it’s memory and OpenGL ES usage. The GARTResident Object Size column shows the amout of texture memory used, in bytes. Divide that by 1024 (i.e. amount / 1024 / 1024) to convert the number to megabytes. Notice how the Frames Per Second drops dramatically while the textures are loading.

Step 5

Happy Optimizing!

11 comments on How to check iPhone texture memory usage with Instruments
  1. Ari Braginsky Says:

    Great post!

  2. iWyre Says:

    [...] Instruments to check iPhone Texture Memory Usage by admin on April 23rd, 2009 A great blog post for anyone doing OpenGL work on the [...]

  3. This Week in iPhone News - April 24/2009 Says:

    [...] How to check iPhone texture memory useage with Instruments Very handy post about how to use Instruments to monitor the memory used by your OpenGL ES textures. [...]

  4. links for 2009-04-25 « Blarney Fellow Says:

    [...] How to check iPhone texture memory usage with Instruments ● Metal Fish Eggs ● zinc Roe Design (tags: iphone opengl memory viapssteam) [...]

  5. rahul Says:

    Its a great tutorial for novice user of instrument, please provide similar tutorial on leak and object allocation. Thanks..

  6. Project Organization and Coding Conventions for iPhone Games ● Metal Fish Eggs ● zinc Roe Design Says:

    [...] Check OpenGL Texture Memory — OpenGL on the iPhone has a soft limit of 24Mb for all textures. If you go above the limit, there’s a massive performance hit. See: How To Check iPhone Texture Memory Usage With Instruments [...]

  7. Skotch Says:

    When I fire up instruments, I don’t see the same settings. Instead, I see “Resource Bytes” under OpenGl Es. Have these changed? Is there any documentation on what each statistic means?

  8. AR Says:

    Fantastic post. Is there any followup tutorial planned for profiling openGL iphone games? There seems to be a distinct lack of material for this topic on the internet (or it’s hidden rather well).

  9. Luke Says:

    Yes, the options seem to have changed with the 3.0 SDK (the post and screenshots were based on the 2.2 SDK). I haven’t done enough OpenGL testing with the 3.0 SDK to know if the “Resource Bytes” column is equivalent to the “GART Resident Object Size” column or not :-( It really would be great if Apple would do some tutorials or screencasts covering this stuff…

  10. Sam Says:

    This still works with the 3.0 SDK, however you must select the app to start befor setting the instruments. When I loaded instruments it didnt’ even have an OpenGL ES option, just an “OpenGL Driver” one which had completely different options. Once I selected my iPhone and the app to start then the “OpenGL ES” option appeared, and I could select the options described exactly as written.

    The step order should now be: 1, 4, 2, 3, 5, and it works perfectly as of Aug 2009.

  11. bada Says:

    Sam, i didn’t see the the GARTResident Object Size at Snow Leopard with Xcode 3.2! Someone have another option to do that?

Your Comment…

You can use these tags: <a> <blockquote> <strong> <em> <strike> <code> <pre> Use <pre lang="LANGUAGE"> for syntax highlighted code blocks.