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 (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
- .NET Debugging : Managed Heap and Garbage Collection
- Context and Interception : Custom Component Services (part 3) - The Transaction Management Service
 
 
Most View
- Understanding Service Broker Constructs (part 4) - Creating the Conversation Initiator
- iOS SDK : Debugging (part 4) - Instruments—Leaks
- Windows Server 2008 Server Core : Performing Application Installations
- Active Directory Domain Services 2008: Enable the Detailed Directory Service Replication Auditing Subcategory
- Exchange Server 2010 : Managing Web and Mobile Access (part 2) - Enabling SSL on Web Sites, Controlling Access to the HTTP Server
- Unit Testing in Visual Studio 2010 (part 1) - Creating unit tests
- Windows Server 2008: Using Event Viewer for Logging and Debugging (part 1)
- Exchange Server 2010 : Upgrading from and Coexisting with Exchange Server 2003 (part 10) - Recipient Update Service Migration
- Microsoft Windows Vista : Using Parental Controls to Restrict Computer Usage
- Windows 8 : Configuring Network Connections (part 2) - Configuring DNS Resolution, Configuring WINS Resolution
Top 10
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 3) - Configuring Recipient Filtering
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 2)
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 1)
- Implementing Edge Services for an Exchange Server 2007 Environment : Installing and Configuring the Edge Transport Server Components
- What's New in SharePoint 2013 (part 7) - BCS
- What's New in SharePoint 2013 (part 6) - SEARCH
- What's New in SharePoint 2013 (part 6) - WEB CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 5) - ENTERPRISE CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 4) - WORKFLOWS
- What's New in SharePoint 2013 (part 3) - REMOTE EVENTS