Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 515885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:40:27+00:00 2026-05-13T07:40:27+00:00

I’m going through Cesarini and Thompson’s Erlang Programming (O’Reilly) and I made a solution

  • 0

I’m going through Cesarini and Thompson’s “Erlang Programming” (O’Reilly) and I made a solution to 4-2 but after playing around with it there are two problems:

  1. Every time I run go/3, “werl.exe” in windows chews up X amount of RAM. Every subsequent call takes up the same amount and it’s never reclaimed.

  2. If I run go(Message,10000,10) it eats up 1.4GB RAM and crashes

I thought that in my second case, Erlang should handle this no problem from what I’ve been reading, so my guess is that I’ve somehow introduced a memory leak? I read the sections on memory leaks and tail recursion and don’t see what I’m doing wrong.

Thanks in advance.

-module(processRing).
-export([waitMessage/0,go/3]).

% Spawn M processes and pass Message around to each process N times
go(Message,M,N) ->

    ProcList = buildList(M),
    [H | T ] = ProcList,
    register(firstProc,H),
    H ! {self(), T, ProcList, Message, N}.

waitMessage() ->
    receive 
        {_, _, _, _, 0} ->
            io:format("end!", []);

        {From, [H|T], AllProcs, Message, N} ->
            %io:format("~w:~w from:~w~n n=~w",[self(),Message,From,N]),
            H ! {self(), T, AllProcs, Message, N},
            waitMessage();

        {From, [], AllProcs, Message, N} ->
            io:format("~w:~w (Last in list) from:~w n=~w~n",[self(),Message,From,N]),
            firstProc ! {self(), AllProcs, AllProcs, Message, N - 1},
            waitMessage();

        Other ->
            io:format("other:~w~n",[Other])
    end.

buildList(N) when N > 0 ->
    [spawn(processRing,waitMessage,[]) | buildList(N - 1)];

buildList(0) ->
    [].
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:40:28+00:00Added an answer on May 13, 2026 at 7:40 am

    ProcList contains the list of Pids of all spawned processes. This list is received by all processes. For your example this means 10.000 x 10.000 Pids for each turn. That’s quite a lot of memory!

    Unless garbage collection can be set to get rid of the list as soon as the list is received, this won’t work… try calling erlang:garbage_collect() before the waitMessage() tail calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.