Apple supplies a number of extra tools in the iOS SDK. One of them, called Instruments, lets you run your app in the simulator or on a device while observing real-time memory usage and the occurrence of memory leaks. For example, you can watch how many objects are being allocated in memory while a program runs. If a particular user operation triggers a significant repeat loop that does not employ an
NSAutoreleasePool object, you will likely observe the number of object allocations and overall memory usage continue to creep upward while the loop works. If so, you’ve spotted a candidate for wrapping inside an autorelease pool.To run your app through Instruments, first make sure that it is in a usable state on the simulator. Then choose Run→Run with Performance Tool→Leaks from the Xcode menubar. Your app will probably run slower than usual as Instruments gathers runtime system data and displays it both in a running graph and a table.
Instruments is an incredibly rich development and testing tool. Explaining how to exploit all its powers would take a separate book. Although the iOS SDK documentation set includes an Instruments User Guide (search for “Instruments”), the guide is not necessarily for the newcomer to the platform. You can, however, get some individual help by asking questions at Apple’s iOS Developer Center forums (iOS developer membership required).
One other helpful tool is available to all users of the SDK. Xcode includes a static analyzer, which goes through your source code in search of problems the compiler does not always locate. For instance, the analyzer (built from an open source tool called CLANG) will spot potential memory leaks in your code. The first time you run your code through CLANG (choose Build→Build and Analyze), you may be shocked at the number of potential leaks (generally unresolved retain counts) it displays in the Build Results window (choose Build→Build Results to show the window). CLANG can display occasional false positives for problems, but you should study each reported issue carefully.
Is it possible for Javascript programmers to learn the iPhone SDK and live to tell the tale? Technology guru Danny Goodman did, and in this book he leaves a well-marked trail for you to follow. Goodman understands the challenges you might face with the SDK, and he introduces Xcode, Objective-C, and Cocoa Touch in a context you'll readily understand. If you're a Javascript programmer and want to take advantage of the iPhone and iPad, iOS 4 SDK is your tool -- and this is your book. Includes full coverage of iOS SDK 4.2.




Help






