Zen API
|
All classes derived from kObject are reference counted. Reference counting can be used to share read-only or thread-safe object instances within different areas of a program.
Initially, the reference count of each object is set to one. The kObject_Share method can be used to increase the reference count, and the kObject_IsShared method can be used to determine if the reference count is currently greater than one. When an object is destroyed (or disposed), the reference count is decremented. The resources associated with an object are deallocated only when the reference count reaches zero.
kObject's reference count is implemented using a 32-bit atomic integer (kAtomic32s). The use of an atomic variable enables reference counting methods to be used safely and efficiently across multiple threads.