In Objective-C there's no owner, everyone borrows objects. You increase retain count (if you want to hold object for longer than lifetime of a function), and you decrease retain count when done.
And there are few methods to increase (retain, init, copy, new, property assignent) and few to decrease count (release, autorelease, nil property assignment).
To me it's that simple.
You'd avoid creating circular structures as much as possible. You can get pretty far that way.
But in the real world, reference-count based GC just has limited usage.
And in theory it doesn't fare much better. Proper garbage collection can have better performance, and does the Right Thing.
The rules are just as simple as C or C++, and Apple explains them far more succinctly:
http://developer.apple.com/library/mac/#documentation/Cocoa/...
Dealing with this sounds like a nightmare in C.
Here's a real life example that I ran into a few years ago when trying to write a largish system using just malloc and free. It was in the world of Conditional Access, and I was doing a cardless system that used a secure tunnel to talk to a server. I had an object that represented the Service Operator, and this object created the secure tunnel to talk with the server representing the service operator at the head-end. It worked just fine most of the time until I tried to handle the case of the command that deleted the representation of the Service Operator in my set top box. When I called Delete on the Service Operator object, my secure tunnel blew up, because it relied on information that was held by the Service Operator object. What I needed was a way of being able to say Delete the Service Operator object, but wait until the tunnel has closed before doing it.
Now, you could just set a special flag in the tunnel object saying "delete the service operator after closing", or you could create a Service Operator callback that is called when the tunnel closes, and it doesn't act on any request to delete until that callback is received - but then what happens if someone other than the tunnel wants to delete the service operator? The callback never comes. It was a version of this system that I used in the end, but it was far more complicated than it would have been with reference counting. The solution when using reference counting is simply to a retain of the ServiceOperator when the tunnel opens, do a release when the tunnel closes, and if the tunnel really wants to delete the service operator, it does a release in mid-communication. As simple as can be.
C's memory management has a simplistic interface: malloc/free. However it operates on the notion of raw memory space. You need to do more work figuring out how much memory you need based on the size of your objects.
C's memory management is not difficult, but it is more involved. The author says it pretty well when he states that Obj-C hits a middle ground between GC and manual memory management. It elevates the control of memory to a level where it makes more contextual sense.
http://developer.apple.com/library/mac/#documentation/Cocoa/...
--------------------
In simplistic form:
A) If a method "begins with" alloc or new, you must release or autorelease.
B) If a method "contains" copy, you must release or autorelease.
C) For every retain message you send to an object, you must balance it out with a release or autorelease (e.g. malloc/free).
D) If a method returns an object to you, and the method name did not match with the "A" or "B" rules, you have received an autoreleased object. This object is guaranteed to exist for the remainder of its identifier's scope.
E) To make an autoreleased object live longer than its identifier's scope, retain it (ensuring to release/autorelease it when finished).
--------------------
There are a few edge scenario's too (described in the link), but that's the gist of it. Also, whenever you put an object inside an NSSet/NSArray/NSDictionary, it's sent a retain message. When said NSSet/NSArray/NSDictionary gets deallocated, it sends a "release" message to all of its members. A lot of other objects act similarly (always documented well by Apple).
At first it's a little challenging to grasp. But after programming for a little while in Obj-C using the Foundation or Cocoa API, you get the hang of it and it comes quite naturally.
In general I've found learning Obj-C with Foundation/Cocoa is difficult at first, mostly from trying to grasp the design patterns Apple has used with OOP. For example, delegate methods, bindings (using KVC/KVO), the responder chain, etc... But after you've learned them, you go "ah ha!!!" and get it. Then things become much easier to code.
On top of that, I have nothing but good things to say about other Apple coders. From bloggers, to StackOverflow users, to IRC; everybody is extremely helpful and pleasant to deal with. :)
That implies you cannot return malloc'ed memory to a caller in C. I doubt many people are willing to live under that restriction.
If you new, alloc or copy, you own the object and must release it. Don't take ownership of delegates. That's about it.
autorelease was added at the same time as the retain/release. @property, on the other hand, came much, much later and is entirely separate.
Obviously it's something any Cocoa developer would want to learn, but it didn't seem necessary in an article trying to prove how basic memory management in ObjC is.
If someone were to write such an article about C, then it would have just one line: if you malloc, then you must free.
If someone were to write such an article about C++, it would be more involved: delete if you new, delete[] if you new[] and then they'd explain auto_ptr and shared_ptr. More complicated that C, but still reasonably easy and you can get automatic memory management.
On the other hand we have Objective-C, where you apparently need at least 11 paragraphs to explain the basics, only to find out that - yes - you still have to call malloc and free only with other names and slightly different behaviour?