[Haskell-cafe] Automatic Reference Counting

Steve Schafer steve at fenestra.com
Sat Jul 2 18:42:24 CEST 2011


On Sat, 2 Jul 2011 16:51:53 +0100, you wrote:

>Apple recently announced a new static analysis in Clang called ARC
>(Automatic Reference Counting).  The idea is to provide what GC
>provides (zero memory management code by the programmer), but not to
>incur the runtime penalty of having to have the GC run.  It seems to be
>extremely effective in objective-C land.
>
>I was wondering if any of the compiler gurus out there could comment on
>the applicability of this kind of analysis to Haskell.  Dropping the GC
>and hence stopping it blocking all threads and killing parallel
>performance seems like nirvana.

Reference counting as a means of lifetime management has been around for
a long time in Microsoft's Component Object Model. And in both
(Microsoft) Visual Basic and (Borland/CodeGear/Embarcadero) Delphi,
reference counting is automatic, in a way that appears to be essentially
identical to what Apple is describing. So, the concept is nothing new;
the new part is that it is being offerred in a C dialect.

>The one major problem that's still left with ARC is that it does not
>solve the retain cycle problem of reference counting.  Programmers must
>insert a "weak" keyword to break cycles in their data graphs.  Could
>even this analysis be automated statically?  Could we put up with a
>language extension that added this annotation?

For handling cycles, there are alternatives to weak references, but I
don't know that any of them is better than weak references. Excluding
weak references, I don't know of a way to deal with cycles that isn't
computationally equivalent to what full-blown garbage collectors already
do, so there's really nothing to be gained there.

If there were a way to do static analysis, there would be no need for
garbage collection as it is currently implemented--the compiler would be
able to insert explicit object lifetime management directly into the
code.

-Steve Schafer



More information about the Haskell-Cafe mailing list