Debugging Cocoa Memory Management

I’ve been trying to learn Cocoa and Objective-C on and off for about a year now. It wasn’t until the past five or six months that I’ve really been able to dedicate the time to climb the steep learning curve required.

One of the big hurdles I’ve faced (and from what I’ve seen others have too) is object reference counting or retain counts. I’ve encountered reference counting before in C++ and in the world of COM on the Windows platform. For some reason, the way Cocoa and Objective-C handles it has proved to confuse me.

The Big Nerd Ranch’s new weblog has a great resource on Debugging Retain Counts.

This is very timely for me. As I’m trying to finish up my first cocoa project, I’m starting to really concentrate on the refactoring and general clean up of my code.

A big part of this process has me concentrating on memory allocation of my objects. When do I allocate? When do I retain? When do I use autorelease?

Now that I know how to debug retain counts, I need a good resource on the best practices of when and how to retain objects.