[erlang-questions] Reference counting instead of GC?
Richard Carlsson
richardc@REDACTED
Thu Jul 3 16:46:39 CEST 2008
Alpár Jüttner wrote:
> Hi,
>
> Did anyone consider replacing the garbage collection with reference
> counting in the Erlang emulator? How difficult would it be to do?
Perhaps not "difficult", but lots of tedious and error-prone work.
> Probably, it isn't worth changing in general, but reference counting has
> some advantages which are important in some special use cases:
>
> * Per process memory pools is not necessary.
> * Message passing (of large data) will be more efficient as
> messages don't have to be physically copied.
> * There is no need for garbage collection. GC is for example a
> major pitfall in hard real time systems (see e.g.
> http://www.erlang.se/workshop/2007/proceedings/05nicosi.pdf )
>
> Here are the drawbacks I can see now:
>
> * Higher memory overhead.
> * However the memory is less fragmented, so we get back
> something in return.
> * It is said to be slower. I'm not absolutely convinced about it
> though.
> * In general, the highest problem with reference counting is that
> in case of cross/circular referencing, dead objects will be left
> in the memory. However, this cannot happen in Erlang due to the
> immutability of the data.
Reference counting would most certainly both be slower and use more
memory, in the cases where it matters the most for Erlang: lists and
tuples, floats, small binaries, and large pids and refs.
On the other hand, large binaries are already handled by reference
counting in the BEAM, so you already have the advantages that you list,
for big objects.
/Richard
More information about the erlang-questions
mailing list