views:

521

answers:

4

While developing my app I have come to realize that the majority of my app crashes have arisen from poor memory management.

I understand I can print or log retain counts through NSLog (@"retain count is:%d",[myInstance retainCount]);

But isn't there a better, less manual method? Possibly a visual representation of your objects and instances?

answered. Cheers, Adam & Jason. :-)

+6  A: 

Use the Leaks and Object Allocation tools through XCode.

Run > Start with Performance Tool > ...
adam
+2  A: 

As Adam suggests, Instruments is a very useful tool for these kinds of things. It's fairly easy to use, but can be a bit overwhelming at first. I suggest perusing the Instruments User Guide as you get started. It's pretty easy to follow and is helpful until you've used Instruments for a while. Even without reading the guide, however, Instruments is still far easier and more intuitive than littering your code with NSLog() calls and trying to parse the output yourself ;)

Jason Coco
+2  A: 

In addition to the other answers, I would highly recommend using clang to do a static memory analysis of your code. It won't catch every memory-management error, but it does catch quite a lot. If your chief problem seems to come from memory management errors, clang will go a long way toward finding those errors. Clang is free, at http://clang.llvm.org/

Tom Harrington
A: 

I also find the NSZombie trick useful for tracking down cases of over-release objects.

Basically the link describes a 'trick' so that release'd objects get replaced by NSZombie objects which if they get released again throw exceptions.

You can then use Instruments to track back to where the object was allocated.

Chris Kimpton