Delegating objects are not considered to own their delegates or data sources. Similarly, controls and cells are not considered to own their targets, and the notification center does not own the observers of notifications. Consequently, for memory-managed code these framework objects follow the convention of not retaining their targets, observers, delegates, and data sources; instead, they simply store a pointer to the object.
Note: In memory management, a nonretained object reference is known as a weak reference, which is something altogether different from a weak reference in a garbage-collected environment. In the latter, all references to objects are considered strong by default and are thus visible to the garbage collector; weak references, which must be marked with the __weak type modifier, are not visible. In garbage collection, retain cycles are not a problem.
The object-ownership policy in memory management recommends that owned objects should be retained and archived unconditionally, and that referenced (but not owned) objects should not be retained and should be archived conditionally. The practical intent of this ownership policy is to avoid circular references, a situation where two objects retain each other. (This is often called a “retain cycle.“) Retaining an object creates a strong reference, and an object cannot be deallocated until all of its strong references are released. If two objects retain each other, neither object ever gets deallocated because the connection between them cannot be broken.
If you create a subclass from a Cocoa framework class with a delegate, data source, observer, or target, you should never explicitly retain the object in your subclass. You should create a nonretained reference to it and archive it conditionally.
Further Reading: For more on the ownership policy, weak references, and circular references in memory management, see "Object Ownership and Disposal" in Memory Management Programming Guide for Cocoa. For a summary of strong references and weak references in garbage collection, see “Garbage Collection for Cocoa Essentials“ in Garbage Collection Programming Guide.
Last updated: 2007-10-31