[erlang-questions] garbage collection questions
Bjorn Gustavsson
bjorn@REDACTED
Tue Oct 2 07:29:32 CEST 2007
Doug Currie <doug.currie@REDACTED> writes:
>
> Two questions:
>
> Why isn't the garbage being collected inside my ns (or mark) loop?
For historical reasons, arithmetic operations never causes a
garbage collection. Instead, if a an arithmetic operation produces
a float or bignum, a "heap fragment" outside of the heap is allocated
for it. Too much data in heap fragments will eventually trigger a GC,
though, but in this case too late.
In R12B, we will change that. Bignums and floats will be put onto the
heap and there will be a garbage collection if the heap is full.
Testing your program in our development version of R12B (I only had
patience to use the argument 3), I see that there are a lot more GCs
but that it actually runs faster than in R11B-5.
By the way, your program will run faster if you define is_prime/2
like this:
is_prime(B, I) -> 0 =:= ((B bsr I) band 1).
The reason is that at most one bignum will be constructed, not two.
/Bjorn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list