Re: Memory leak in for loops
Sandino Araico Sánchez wrote: >1. > #!/bin/bash >2. > >3. > for i in {0..15000} ; do >4. > echo $i > /dev/null >5. > done > > > > Repeat-By: > Run the script above and the process starts leaking memory very > fast. > > You know what a memory *leak* is, yes? mallocs() without proper free()s. What you mean is that your memory is used. Feel free to calculate the memory that is needed to store the string representation of {0..15000}, I think you will get a number near your RAM size. J.
Re: Memory leak in for loops
Jan Schampera schrieb: Sandino Araico Sánchez wrote: 1. #!/bin/bash 2. 3. for i in {0..c} ; do 4. echo $i > /dev/null 5. done Repeat-By: Run the script above and the process starts leaking memory very fast. You know what a memory *leak* is, yes? mallocs() without proper free()s. What you mean is that your memory is used. Feel free to calculate the memory that is needed to store the string representation of {0..15000}, I think you will get a number near your RAM size. J. ... and try for (( i = 0; i < 15000; ++i )) do echo $i > /dev/null done instead. Consumes nearly no memory at all. Cheers, Bernd -- Bernd Eggink http://sudrala.de
Re: Memory leak in for loops
OK. Thanks. I have understood the difference. Bernd Eggink wrote: > Jan Schampera schrieb: >> Sandino Araico Sánchez wrote: >> >>>1. >>> #!/bin/bash >>>2. >>> 3. >>> for i in {0..c} ; do >>>4. >>> echo $i > /dev/null >>>5. >>> done >>> >>> >>> >>> Repeat-By: >>> Run the script above and the process starts leaking memory very >>> fast. >>> >>> >> >> You know what a memory *leak* is, yes? mallocs() without proper free()s. >> >> What you mean is that your memory is used. Feel free to calculate the >> memory that is needed to store the string representation of >> {0..15000}, I think you will get a number near your RAM size. >> >> J. >> >> > > ... and try > > for (( i = 0; i < 15000; ++i )) > do > echo $i > /dev/null > done > > instead. Consumes nearly no memory at all. > > Cheers, > Bernd > > -- Sandino Araico Sánchez http://sandino.net