On 2016-09-15 17:07, Michael Heerdegen wrote: > Clément Pit--Claudel writes: > >>> but the same applies to a list. >> >> Not exactly: the list needs to be fully built before you iterate >> over it. That's when the memory problems occur. So yes, during >> iteration you can discard the cons cells that you've already seen >> in both cases, but in the list case these cells need to all be >> constructed and kept in memory beforehand. > > But I think what John said is still a valid argument: If you > construct a stream of lines of a process's output (just for example), > of, say, 10000 lines, you create 10000 new objects (strings), and you > discard 10000 - n of them. They all need to be garbage collected. This is orthogonal to the list-vs-stream debate, isn't it? > This will not only take a large amount of time - garbage collection > happens not all the time, so memory will be filled to a certain > amount as well. But I think the impact of garbage collection of that > many objects is a more serious problem than memory usage anyway. [citation needed] :) Garbage collection costs time; memory costs, well, memory. It's just a trade-off. > Instead, a simple loop incrementing a position variable or something > like that might be more appropriate (efficient). Sure, but again: how is this related to lists vs strings? Lists need to be garbage collected just the same. > Instead, a simple loop incrementing a position variable or something > like that might be more appropriate (efficient). I'm not sure what you mean :\ Are you saying that sometime streams are not the right solution for a given problem? I agree fully :) Cheers, Clément.