Question

I understand that NSObject does not have a retainCount instance variable - in fact it has no instance variable relating to its lifetime or reference counted environment. My question is therefore, how does NSObject (or any object for that matter) keep track of its own reference count without an ivar?

More generally, what other systems are there for creating a reference counted environment without the use of an explicit reference-counting instance variable?

Was it helpful?

Solution

First, you should never count on a specific implementation because it could change, and it is really irrelevant for most purposes.

Anyway, the current implementation is via an associated reference count, basically via a hash table, hashing the object pointer to a reference count.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top