| < Previous PageNext Page > |
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 these framework objects follow the convention of not retaining their targets, observers, delegates, and data sources; instead, they keep a weak reference to them—that is, they store a pointer to the object.
The object-ownership policy recommends that owned objects should be retained and archived unconditionally, while 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. 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 weak (non-retained) reference to it and archive it conditionally.
Further Reading: For more on the ownership policy, weak references, and circular references, see "Object Ownership and Disposal" in Memory Management Programming Guide for Cocoa.
| < Previous PageNext Page > |
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-12-20)
|