tags:

views:

13128

answers:

7

Does Apple's Xcode development enviroment provide any tools for memory leak detection? I am especially interested in tools that apply to the iPhone SDK. (currently my favorite platfrom for hobby programming projects) Documentations/tutorials for said tools would be very helpful.

+2  A: 

ObjectAlloc and MallocDebug should both be of help to you. If you installed the entire SDK, they will be found in Developer->Applications->Performance Tools.

Their names give you a pretty good clue as to their functions, OA, tracks the objects create and MA is a general memory leak tool.

I haven't tried them with iPhone development yet, but I have to believe that they would work there as well.

Assuming you have registered for ADC iPhone developer site, here the link to follow:Instruments User Guide

KevDog
+8  A: 

Try Apple's Instruments utility, found in /Developer/Applications/.

A commercial alternative is OmniObjectMeter.

titaniumdecoy
+2  A: 

You can run the tools within XCode over menu -> run -> start with performance tool -> ...

catlan
+16  A: 

There is one specifically called 'Leaks' and like a previous poster said, the easiest way to run it is straight from Xcode: run -> Start with Performance Tool -> Leaks. It seems very good at detecting memory leaks, and was easy for a Non-C Head like me to figure out.

rustyshelf
Note that in recent versions of OS X, this is actually part of Instruments. This is an excellent way to find leaks.
Quinn Taylor
+4  A: 

Clang is an awesome static code analyzer to find bugs in objective-c code:

http://clang.llvm.org/StaticAnalysis.html

lajos
That's like saying "gcc is a code coverage too" because it includes gcov. Clang is the name of the overall LLVM C front-end project. The static analyzer is "the Clang static analyzer."
Chris Hanson
Chris is correct (of course) but things have changed a bit since then. In Snow Leopard, Xcode 3.2 will integrate the Clang static analyzer in a beautiful way, and it can indeed be a wonderful way to find leaks.
Quinn Taylor
+1  A: 

When using rustyshelf's solution make sure you test on the iPhone and not on the simulator. Memory usage is dramatically different.

schwa
It's true that runtime memory usage is different, but the paradigm(s) for managing memory work for all Objective-C applications. A leak is a leak, even though it may manifest itself in different ways or at odd times.
Quinn Taylor
+1  A: 

Made a sum up of the main memory leak tools: http://bcaccinolo.wordpress.com/2010/09/15/iphone-essential-performance-tools-list/

Benoit Caccinolo