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
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Most View
- Exchange 2007: How Do I Modify a Database Size Limit?
- Windows 7 : Enhancing Your Browsing Security (part 1) - Blocking Pop-Up Windows
- Enable the Global Audit Policy by Using the Command Line
- Windows Phone 7 : Updating Your Phone Software
- SOA with .NET and Windows Azure : WCF Discovery (part 1) - Discovery Modes
- Microsoft ASP.NET 3.5 : WCF Services for ASP.NET AJAX Applications
- Securing Windows 7 : Thwarting Snoops and Crackers (part 2) - Locking Your Computer Manually, Automatically
- Windows 7 : Accessing a Shared Printer
- SQL Server 2008 : Data Encryption - SQL Server Key Management
- Windows 7 : Firing Up the Registry Editor