Garbage collection of binaries

Jesper Wilhelmsson jesperw@REDACTED
Thu Oct 16 13:49:15 CEST 2003

On Tue, 14 Oct 2003, Sean Hinde wrote:

> Is there not some mechanism which could be introduced to specifically
> check for processes growing in this way - I don't know, perhaps every
> time a very large binary is assigned on the heap check to see if it
> might be a good time do do a "survival" GC? Maybe a running total could
> be kept of binaries assigned over a certain size? It would seem to have
> relatively little overhead compared to the actual operation of making a
> very large binary, and it would protect against this case quite a bit
> of the time.
> Sean

To do an off-heap collection (to reclaim objects that is not allocated in
the heap, ie binaries), and find all references to these objects (or to
see that there are no references), you have to look through all memory
that can contain these references. That is, all heaps and all stacks. This
would be expensive, but maybe not SO expensive compared to creating a
large binary.
In the private heap architecture, it would be possible to mark all
processes that have had a reference to a binary and only scan those
processes. This is not possible in a shared heap architecture though.

If this is needed in an application or not, is verry much depended on the
application. Perhaps it is better if the programmer who knows if it is
needed or not, calls garbage_collect() in concerned processes before
creating a large binary, the cost would be the same if it was done under
the surface anyway. The difference in this case is, that the programmer
probably knows that it is only these three processes that have touched the
large binaries and needs collections. The system would only know that
there are twenty processes that have binaries - they all need collection.
___(  |_______________________  _______________________________________________
    | | ,---. ,--.,--.,--.   ( (
    | ||  _  || o ) o ) p )   ) ) "Beware of bugs in the above code;
    | || (_) || r'| r'| -×--.( (  I have only proved it correct, not tried it."
o,--' | `---' |_| |_| `-----' ) )                               -- Donald Knuth
_`----'______________________( (_______________________________________________
Jesper Wilhelmsson, jesperw@REDACTED                         +46 (0)18 471 1046
Computing Science Department, Uppsala University, Sweden     +46 (0)733 207 207

More information about the erlang-questions mailing list