Xcode Debug Tools

Xcode has some good built-in debug tools that can help you find problems. You should get familiar with them.

Memory Debug tools

The Malloc Debug feature will help catch buffer overruns and other memory allocation errors. It works by replacing the system's memory allocators with a (slower) custom version with debugging feature. It makes it more likely that bad memory accesses will cause memory access violations instead of just silently being wrong. (The movie below shows these steps in action).

  1. Click on the active scheme in the window title bar and choose Edit Scheme...

  2. Choose Run, then choose Diagnostics

  3. Under Memory Management, turn on "Enable Malloc Scribble", "Enable Malloc Guard Edges", and "Enable Guard Malloc".

  4. Run your project again.

If you find any errors, congratulations, you've saved yourself some weird crashes. When I'm working on any program, I run with this on 90% of the time.

Look here for more information about Malloc Debug.

Use Static Analisis

In your Xcode project, choose Product->Analyze. This actives a feature of the compiler that will find logical coding errors. In my experience, the things that it points our are almost always either actual bugs or at very least bad coding practice. When I ran it on my Mac OS X port of Invaders, it showed me a leak of a Core Foundation object that I missed.

← Prev: iphone-port-pt-3---viewcontroller.m   Next: iphone-port-pt-4---touch-handling →


Post questions or comments on Twitter @realemulator101, or if you find issues in the code, file them on the github repository.