Well, I think I have to apologize. I had the impression that the machine I was working on was 64-bits. It is 32-bits, so, yes, 5 words per character means the list from the lists:seq/2 resides fully in memory. My bad, sorry.<div>
<br></div><div>I did the test again using the loop from Richard's test and, indeed, I got about 80 MB memory consumption for 10^7 characters which is consistent with 2 words per character in the list.</div><div><br></div>
<div>Now, to answer how free can be used in such a test:</div><div>1. execute command: watch -n 1 'free -m' (every 1 second calls free -m (output in MB) and reports its output);</div><div>2. stabilize your OS by killing all the processes which have a non-constant memory usage at the level of MB (that is, for several seconds the output of the previous command should remain constant);</div>
<div>3. start an Erlang shell (that adds usually something like 4 MB to the used memory);</div><div>4. load the module (usually not visible in the output of (1), but it may add 1 MB, depending on the system state by that time);</div>
<div>5. execute `<module>:loop(10000000), ok.';</div><div>6. the difference in between the output from (1) after step (5) and the output from (1) after step (4) is giving the memory used by Erlang for the list (+ some overhead).</div>
<div>This is much of how Richard did it in Erlang, but using external tools to monitor the RAM consumption. I repeated several times this and I got almost the same result (1 MB error, but that may be an artifact of the shell or system).</div>
<div><br></div><div>Again, I am sorry for my mistake thinking that the sequence list was empty when lists:map/2 exited, but I was really under the impression that the machine I was working on is 64-bits (1 word = 8 B). And thank you for spotting my mistakes in judgement.</div>
<div><br></div><div>CGS</div><div><br></div><div><br><br><div class="gmail_quote">On Tue, Jul 10, 2012 at 3:21 AM, Richard O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On 9/07/2012, at 10:34 PM, CGS wrote:<br>
> > About the two lists you were speaking about (I suppose you were referring to the output of lists:map/2 and lists:seq/2), the second is destroyed as soon as lists:map/2 exits.<br>
><br>
> No it isn't.  It is only reclaimed when the garbage collector runs.<br>
><br>
> That is a bit puzzling.<br>
<br>
</div>It seems that you are muddling up "is LIVE" with "EXISTS".<br>
When you compute<br>
        map(F, L)<br>
and there are no other references to L anywhere,<br>
L becomes *DEAD* as soon as the call to map/2 completes.<br>
(In fact, each cell of L becomes dead in turn during the<br>
call.)  But DEAD and DESTROYED are very different properties.<br>
L is not "destroyed" until the garbage collector runs;<br>
until the garbage collector runs the cells of L still occupy<br>
space on the heap.  When, if ever, that space is reclaimed<br>
depends on how much other need there is for it.<br>
<div class="im"><br>
> Looking at the code for lists:map/2:<br>
><br>
> map(F, [H|T]) -><br>
>     [F(H)|map(F, T)];<br>
> map(F, []) when is_function(F, 1) -> [].<br>
><br>
> I can see that when lists:map/2 exits, the only remaining list is an empty list.<br>
<br>
</div>No you can't see that, because there is nothing in the code<br>
for map/2 to release any storage whatever.<br>
<div class="im"><br>
> I might be wrong, but I see only one word remaining for the garbage collector to take care of.<br>
<br>
</div>What do you think makes the other words go away?<br>
<div class="im">><br>
><br>
> You got the result from process_info, I got it from `free' under Linux.<br>
<br>
</div>Not the best way to do it.  That tells you how much memory<br>
the operating has handed out but not to which process; even<br>
ps -o size tells you only how much memory Erlang has claimed from<br>
the operating system, and nothing about what Erlang is doing with<br>
that memory.<br>
<br>
<br>
</blockquote></div><br></div>