Programming4us
         
 
 
Programming

iOS SDK : Debugging (part 4) - Instruments—Leaks

8/17/2011 11:38:35 AM

Instruments—Leaks

Instruments is a powerful suite of debugging and testing tools. Tools include Activity Monitor, CPU Sampler, Leaks, Object Allocations, Core Animation, OpenGL ES, and System Usage (Figure 12).

Figure 12. Instruments

Note

For more information on Instruments, refer to Apple’s documentation “Instruments User Guide,” available online or via the Instruments Help menu.


However, one tool worth introducing you to here is Leaks. You can use Leaks without knowing much about it. The Leaks instrument allows you to easily find memory leaks in your application. It tells you how many leaks occurred, each leak’s size, the address of the leak, and the leaked object’s type. Using Leaks is fairly intuitive—rather than explaining, let me simply explain by example through the following application.

Try This: Find a Memory Leak

In the following task, you find memory leaks using the iPhone Simulator.

Find a Memory Leak on iPhone Simulator

  1. Create a new Utility application named Sieve.

  2. Create a new Objective-C class named FooBar.

  3. Open FlipsideViewController.m and implement the viewDidAppear method (Listing 6). Don’t forget to import FooBar.h.

    Listing 6. The viewDidAppear method
    -(void) viewDidAppear:(BOOL) animated {
    FooBar * myFooBar = [[FooBar alloc] init];
    }

  4. Select Edit Active Scheme from the pull-down menu. Click Launch in the left column; then select the Instruments radio button and select Leaks from the pull-down menu. Click OK to save your changes to the scheme.

  5. Run the application. Ignore the warning informing you that you never use the FooBar instance in viewDidAppear. Note that when you’re using Instruments, Xcode will run the iPad Simulator rather than the iPhone Simulator. You’ll also see the Instruments application automatically launch.

  6. Click Info and Done repeatedly for about 30 seconds. When finished, click Stop in the Instruments window (Figure 13).

    Figure 13. The Leaks panel
  7. Click Leaks, and a detailed list of the leaked objects appears. Click one of the leaked objects.

  8. Select View | Extended Detail from the main menu, and a call stack appears on the window’s right (Figure 14).

    Figure 14. The Leaks panel showing extended details
  9. Double-click one of the leaks, and the source code will display with the line allocating and initializing FooBar (Figure 15).

    Figure 15. Leaks showing source code where the object was allocated
Other -----------------
- iOS SDK : Debugging (part 3) - NSZombieEnabled
- iOS SDK : Debugging (part 2) - Watchpoints
- iOS SDK : Debugging (part1 )
- iOS SDK : Installing Applications on an iPhone
- Software Testing with Visual Studio Team System 2008 : Web Testing - Recording a test
- Software Testing with Visual Studio Team System 2008 : Unit testing web services & Code coverage unit test
- .NET Debugging : Introduction to the Tools - SOS & SOSEX
- .NET Debugging : CLR 4.0 - Synchronization & Interoperability
- iPhone Programming : Connecting to the Network - Getting Data from the Internet
- iPhone Programming : Connecting to the Network - Sending Email
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Check Results
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Read and Write Files
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Get Dates and Times
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Work with Text
- A Technical Overview of the Mobile Web : THE TECHNICAL CHALLENGES OF MOBILE DEVICES (part 2)
- A Technical Overview of the Mobile Web : THE TECHNICAL CHALLENGES OF MOBILE DEVICES (part 1) - Physical Constraints
- Parallel Programming with Microsoft Visual Studio 2010 : Task Parallelism - Unhandled Exceptions in Tasks
- Parallel Programming with Microsoft Visual Studio 2010 : Introduction to Parallel Tasks
- jQuery 1.3 : DOM Manipulation - Moving elements
- .NET Debugging : Introduction to the Tools - .NET 2.0—Redistributable & .NET 2.0—SDK
 
 
Most View
- SQL Server Integration Services : Logged and Nonlogged Operations
- Windows Server 2008 : Controlling Access to Web Services (part 8)
- An OLAP Requirements Example: CompSales International (part 5) - Creating the Other Dimensions
- Cloud Security and Privacy : What Is the Data Life Cycle?
- Windows Phone 7: Posting to Facebook or Windows Live
- Developing an SEO-Friendly Website : Root Domains, Subdomains, and Microsites (part 1)
- Microsoft Dynamics AX 2009 : Working with Forms - Adding a Go to the Main Table Form link
- SQL Server 2008 : Implementing Transactions - Transaction Traps
- Encryption basics for SQL Server : Key Maintenance
- Windows 7 : Thwarting Spam with Windows Live Mail’s Junk Filter (part 2) - Blocking Countries and Languages
Top 10
- Windows Server 2003 : The Terminal Services Gateway (part 2)
- SharePoint 2010 : Authoring Pages - Create a New Page (part 1)
- Build Mobile Websites and Apps for Smart Devices : Design for Mobile - Standing on the Shoulders of Giants
- jQuery 1.3 : AJAX - Additional options
- SQL Server 2008 : Managing Security - Service Accounts and Permissions
- Sharepoint 2010 : Optimizing Outside of SQL Server
- Exchange Server 2010 : Manage Web-Based Email Access (part 1) - Configure OWA URLs
- SQL Server 2008 : Developing Custom Managed Database Objects (part 4) - Developing Managed User-Defined Types
- Sharepoint 2010 : Change or Remove a Column in a List or Document Library
- Windows7: Troubleshooting Networking from the Command Line (part 1)