Aggressive GC? Was Re: Untimely garbage collection
Bjorn Gustavsson
bjorn@REDACTED
Sun Jul 14 17:32:38 CEST 2002
Answer to the part about the GC:
Scott Lystig Fritchie <fritchie@REDACTED> writes:
> While hacking drivers, I've come across a GC question, similar to
> Shawn's, that I cannot answer.
>
> Consider this code snippet:
>
> iolist2binary(B) when binary(B) ->
> {B, size(B)};
> iolist2binary(L) when List(L) ->
> B = list_to_binary(L),
> {B, size(B)}.
>
> foofoo(Port, IOList) when port(Port) ->
> {IOListBinary, IOListBinaryLen} = iolist2binary(IOList),
> C = [ <<?S1_FOOFOO, IOListBinaryLen:32/integer>>, IOListBinary],
> erlang:port_command(Port, C),
> %% Vulnerability window begins here?
Yes. If your driver haven't incremented the reference counter, you are
in trouble.
The compiler knows that the variables C and IOListBinary will not be
used anymore; therefore, at this point no reference to them will
be kept, and the next garbage collection the reference counts
for the binaries will be decremented.
> get_port_reply(Port).
>
> get_port_reply(Port) ->
> receive
> {Port, ok} -> ok;
> [...]
>
/Bjorn
--
Björn Gustavsson Ericsson Utvecklings AB
bjorn@REDACTED ÄT2/UAB/F/P
BOX 1505
+46 8 727 56 87 125 25 Älvsjö
More information about the erlang-questions
mailing list