Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Object life cycle
An object’s life cycle—that is, its runtime life from its creation to its destruction—is marked or determined by various messages it receives. An object comes into being when a program explicitly allocates and initializes it or when it makes a copy of another object. An object can also begin its runtime life during unarchiving, when it is asked to decode itself from the archive byte stream. If an object was unarchived from a nib file, it receives an
awakeFromNib message after all objects in the nib file have been loaded into memory.
After the creation and initialization phase, an object remains in memory as long as its retain count is greater than zero. Other objects in the program may express an ownership interest in an object by sending it
retain or by copying it, and then later relinquish that ownership interest by sending
release to the object. While the object is viable, a program may begin the archiving process, in which the object encodes its state in the archive byte stream. When the object receives its final
release message, its retain count drops to zero. Consequently, the object’s
dealloc method is called, which frees any objects or other memory it has allocated, and the object is destroyed.