I read that (from a book written by Kazuki Sakamoto and Tomohiko Furumoto) on runtime iOS maintains a hashtable
with object's address as key and that object's retain count as value.
Like below:
key(object's addr) value(reference count)
0x7fff59a7ba88 2
0x7fa84b4b2c10 0
...
And iOS runtime would check the table once a while to see if any key with value equals zero, meaning some objects should be released, then iOS would remove that key-value pair from table and call dealloc
to release the object's memory.
If this theory is correct, then my question is that at what time, with what frequency system would check the reference count hashtable
? Each runloop
? Or iOS wouldn't check the table at all but only it's automatically done?
UPDATE:
I just corrected my description which should have nothing to do with ARC or MRC, it's more about reference counting on runtime.
That sort of behaviour sounds more like garbage collection, and isn't exactly how ARC works.
ARC's behaviour is completely deterministic: it tracks the number of strong
references to an object, and once that count hits 0, the object is immediately deallocated. You can read about the implementation details here.