[Haskell-cafe] Automatic Reference Counting

Chris Smith cdsmith at gmail.com
Sat Jul 2 18:52:47 CEST 2011


On Sat, 2011-07-02 at 17:35 +0100, Thomas Davie wrote:
> It's interesting that you cite that GC is both faster and lower memory
> overhead – Apple's stated reasons for implementing this were that GC
> was both too slow and too memory intensive to use sensibly on iDevices
> and that ARC was both faster and less memory intensive.

This is a little more complex that just "better" or "worse".  The speed
and memory overhead of reference counting depend on what percentage of
your data structures are pointers, and of your program is performing
pointer updates.  Presumably, iOS developers would try to avoid a lot of
small heap allocations, and instead use packed data structures with
in-place updates to larger contiguous blocks of memory.  In that case,
it's possible that reference counting is much faster and reduces memory
usage compared to garbage collection.  This is certainly not the case in
a typical functional language, though.

When asking about memory usage, you also want to distinguish between
"hot" memory usage (how much memory is actively used and so we want it
to fit in cache) and overall memory usage (total heap size, even though
a lot of it may be swapped out to disk on a desktop).  Garbage
collection typically increases the overall heap size, but is better than
reference counting when it comes to reducing the size of the "hot" area
of memory.

So basically, I wouldn't call Apple's claims unusual when they are made
for iOS and Objective C (though "garbage collection is too slow to use
sensibly on iDevices" is definitely pushing the ridiculous side of
things), but I also wouldn't expect their rather specific environment to
carry over to general purpose computing, or especially to Haskell.

-- 
Chris Smith




More information about the Haskell-Cafe mailing list