News for hackers. Stuff that matters.
Re:Objective-C Memory Management For Lazy People by pornel on Thursday December 09, 2010 @05:19AM (#1986879)
For me "if you malloc, then you must free" is much harder, because you have to know whether ownership was passed to you, who else might be using object when you free it, etc.

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.

Re:Objective-C Memory Management For Lazy People by schumihan on Thursday December 09, 2010 @05:38AM (#1986919)
Reference count based GC? How would you deal with circular reference?
Re:Objective-C Memory Management For Lazy People by eru on Thursday December 09, 2010 @10:02AM (#1987655)
You don't.

You'd avoid creating circular structures as much as possible. You can get pretty far that way.

Re:Objective-C Memory Management For Lazy People by schumihan on Thursday December 09, 2010 @10:38PM (#1990492)
It's very difficult to avoid it when thing goes complicating. A may reference B, B may reference C, ... and somewhere, X may reference back to A. If this strategy makes sense for big project, many hackers work with C++ can use it either, as the performance overhead is very low.

But in the real world, reference-count based GC just has limited usage.

Re:Objective-C Memory Management For Lazy People by eru on Friday December 10, 2010 @06:48AM (#1991357)
> 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.

Re:Objective-C Memory Management For Lazy People by xsmasher on Thursday December 09, 2010 @12:24PM (#1988214)
Retain your children but not your parents; or do you mean a group of "peers" who retain each other? They should probably be in some kind of collection that retains them All.