3 ms·
Your original argument failed to define "worst-ness", but your followup implies a definition: Your opinion of the relative difficulty of comprehension. The C m
by ankhmoop 18y ago
Your original argument failed to define "worst-ness", but your followup implies a definition: Your opinion of the relative difficulty of comprehension.
The C methodology you have presented ("... malloc() and its eventual free() are both in the same function") constrains ownership knowledge to a single function by simply disallowing more complex constructs (such as shared references held by container classes). This results in your C methodology providing significantly less functionality as compared to reference counting.
Moreover, Objective-C's reference counting rules are logical, consistent, and short.
- All objects are allocated with a reference count of 1.
- All objects will be deallocated when their reference count reaches 0.
- If you receive an object reference that you did not allocate, and you wish to maintain a reference to that object beyond the current scope, you must increment the reference count. Doing so will ensure that should the object's reference count be decremented elsewhere, the object will remain valid.
- If you allocate an object or increment an object's reference count, it will not be deallocated until you decrement the reference count.
Those rules -- coupled with utilities such as NSAutoreleasePool -- permit simple, language-wide ownership invariants. This is something that can not be achieved with "malloc/free".
Lastly, most "newbie" programmers of any persuasion will necessarily have difficulty with basic language constructs, and will be considerably worse off if they have not have spent sufficient time studying the basic language documentation:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-SW1 http://developer.apple.com/documentation/Cocoa/Conceptual/Me...