[erlang-questions] Recursive Heap Allocation

Bob Ippolito bob@REDACTED
Mon Jul 23 22:04:26 CEST 2012


You're probably generating output too fast, there's no flow control in
io:format/2. You can generate things to print much faster than they get
printed, which results in the io server accumulating so many messages in
its mailbox that you eventually run out of memory and/or the machine grinds
to a halt due to swapping.

On Mon, Jul 23, 2012 at 12:50 PM, Greg Martin <greg@REDACTED> wrote:

> I'm just learning erlang using Erlang R15B01 (erts-5.9.1) on Windows. I'm
> wondering why ipv4_addrs:test(ipv4_addrs:first()) leads to the crash below
> and how it can be called so that it doesn't. Thanks.
>
> {1,2,22,127}
> {1,2,22,128}
> {1,2,22,129}
> {1,2,22,130}
> {1,2,22,131}
> {1,2,22,132}
> {1,2,22,133}
> {1,2,22,134}
>
> Crash dump was written to: erl_crash.dump
> eheap_alloc: Cannot allocate 373662860 bytes of memory (of type "heap").
>
>
> Abnormal termination
>
>
> -module(ipv4_addrs).
>
> -export([first/0, next/1, test/1]).
>
> first()->
>         { 1,1,0,0 }.
>
> next( { 255, 255, 255, 255 } ) -> done;
> next( { 9, 255, 255, 255 } ) -> { 11, 0, 0, 0 };
> next( { 172, 15, 255, 255 } ) -> { 172, 32, 0, 0 };
> next( { 192, 167, 255, 255 } ) -> { 192, 169, 0, 0 };
> next( { First, 255, 255, 255 } ) -> { First + 1, 0, 0, 0 };
> next( { First, Second, 255, 255 } ) -> { First, Second + 1, 0, 0 };
> next( { First, Second, Third, 255 } ) -> { First, Second, Third + 1, 0 };
> next( { First, Second, Third, Fourth } ) -> { First, Second, Third, Fourth
> +
> 1 }.
>
> test(done) -> done;
> test(Addr) ->
>         io:format("~p~n", [Addr]),
>         Next = next(Addr),
>         test(Next).
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120723/e3f299f8/attachment.htm>


More information about the erlang-questions mailing list