Skip navigation.
 
mlRe: upper limit on retain count
FROM : Shaun Wexler
DATE : Tue Apr 19 21:05:59 2005

On Apr 19, 2005, at 8:45 AM, John Stiles wrote:

> You know, the computer only has 4 billion bytes of memory, and even
> the most trivial of objects is 8 bytes (it needs an isa and a
> refcount).


Actually, the smallest objects are just 4 bytes , with an implied
1 reference.  Foundation adds the object's id to an "extra ref count"
maptable to add any additional ref's, which is why retain/release is so
expensive, thus inline refcounts are preferred for performance reasons.
  Apple's malloc implementation is guaranteed to return buffers as
multiples of 16-bytes, vec-aligned, so all objects are at least 16
bytes, thus you always have 3 extra int's or floats to play with. 
FWIW, my base framework creates all cache-aligned/sized objects with a
noticeable performance increase, as well as atomicity benefits that
facilitates known ivar alignments and access grouping.

> FWIW, to answer the original question:
> - refcounts are 32-bit ints
> - I am not 100% sure, but I believe they cap at 4 billion (as opposed
> to overflowing)


Most CF container classes use a long long (64 bit) inline ref count,
and many AppKit classes use a shorter-than-32-bit inline ref count,
with a designated bit for "refCountOverMax" that (assuming) either
leaks the object or defers to the default/super refcount for the
overage.
--
Shaun Wexler
MacFOH
http://www.macfoh.com

Related mailsAuthorDate
mlupper limit on retain count Ivan S. Kourtev Apr 18, 22:43
mlRe: upper limit on retain count Daniel Jalkut Apr 19, 07:05
mlRe: upper limit on retain count John Stiles Apr 19, 17:45
mlRe: upper limit on retain count j o a r Apr 19, 18:19
mlRe: upper limit on retain count Axel Andersson Apr 19, 18:44
mlRe: upper limit on retain count Ali Ozer Apr 19, 18:46
mlRe: upper limit on retain count Ondra Cada Apr 19, 18:57
mlRe: upper limit on retain count Ivan S. Kourtev Apr 19, 20:30
mlRe: upper limit on retain count Ondra Cada Apr 19, 20:55
mlRe: upper limit on retain count Shaun Wexler Apr 19, 21:05
mlRe: upper limit on retain count Shaun Wexler Apr 19, 21:09
mlRe: upper limit on retain count Scott Ribe Apr 23, 00:25
mlRe: upper limit on retain count Bob Ippolito Apr 23, 00:40
mlRe: upper limit on retain count Scott Ribe Apr 23, 00:51
mlRe: upper limit on retain count Bob Ippolito Apr 23, 06:57
mlRe: upper limit on retain count Johnny Deadman Apr 23, 18:44