Garbage collection of binaries

Joachim Durchholz joachim.durchholz@REDACTED
Sun Oct 19 01:33:44 CEST 2003

Jesper Wilhelmsson wrote:
> Joachim Durchholz wrote:
>> Jesper Wilhelmsson wrote:
>>> Binaries are referenced counted and are removed when their conter
>>> reach zero.
>> This gives me another approach: when you're done with a binary,
>> zero out all references to it. The binary will go away immediately.
> Well.. The only place where the reference count is decremented is in
> the GC and when a process dies.

Hmm... If binaries are reference counted, this sounds as if the 
following scheme is in effect:
   +----------+     +----------------+     +--------+
   |  Erlang  | --> | administrative | --> | binary |
   | variable |     |      data      |     |  data  |
   +----------+     +----------------+     +--------+
where "administrative data" contains the reference count, and maybe
additional internal data ("administrative data" and "binary data" might
actually be a single block of data).
I see two ways of getting rid of the leftmost reference:
1. If the variable is mutable, assign something else to it.
2. If it is immutable, make sure it's a local variable so that it will
die as soon as it goes out of scope.

None of these solutions is very satisfactory, but I don't see any other 
ways of solving the problem from within the application.
Solving it in the GC would be better, of course, but not everybody can 
easily do that :-)

> To manually decrement the reference count and promise the system to
> never use the address again is not a verry functional way of doing
> things.

Such an approach would not work well with any garbage-collected system,
functional or not.
Of course, it's not what I suggest.


More information about the erlang-questions mailing list