Memory management
One feature of the Cocoa environment that is, if not unique, certainly unusual is its facility for managing dynamically allocated memory. Cocoa's NSObject class, from which all Cocoa classes, both vendor and user, are derived, implements a reference counting scheme for memory management. Every object has a retain method and a release method, and an instance variable accessible through the retainCount accessor method. A newly allocated object, created with alloc, has a retain count of one. Sending that object a retain message increments the retain count, while sending it a release message decrements the retain count. When an object's retain count reaches zero, it is deallocated and its memory is freed. (Deallocation is to Objective C objects as destruction is to C++ objects. The dealloc method is functionally equivalent to a C++ destructor.)
In addition to manual reference counting, application programmers may choose to make use of autorelease pools. Sending an object an autorelease message puts that object's deallocation under the control of the thread's global autorelease pool. The autorelease pool releases an object some time after program flow has passed out of the block where that object was autoreleased.
Cocoa gives the programmer the choice of whether to manually manage his objects or not. Opinions on this are divided. Some say that Cocoa's memory management is superior because it allows the programmer to have precise control over when his objects are deallocated, but does not burden him with the necessity of doing so for every object a program allocates. Others say that the whole mess is unnecessary, and that Java-style automatic garbage collection is superior, because it removes the possibility of programmer error in memory management.
Implementations
Java bindings for the Cocoa frameworks are also available. However the frameworks themselves are written in Objective-C and hence Objective-C is presently the preferred language for the Cocoa applications.
An open source implementation of the OpenStep specification is available under the name GNUstep.
External links