[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Memory leak in for loops
From: |
Mike Frysinger |
Subject: |
Re: Memory leak in for loops |
Date: |
Mon, 4 May 2009 18:53:28 -0400 |
User-agent: |
KMail/1.11.2 (Linux/2.6.29.2; KDE/4.2.2; x86_64; ; ) |
On Thursday 30 April 2009 05:56:02 Jan Schampera wrote:
> Sandino Araico Sánchez wrote:
> > 1.
> > #!/bin/bash
> > 2.
> >
> > 3.
> > for i in {0..150000000} ; 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..150000000}, I think you will get a number near your RAM size.
granted his example is wrong and his reasoning incorrect, there may actually
be a leak here ...
bash-4.0$ ps -p $$ -F
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
vapier 27999 16493 0 5675 3052 1 18:51 pts/1 00:00:00 bash --norc
bash-4.0$ for n in {0..150000000} ; do echo $n; done
<wait a few seconds>^C
bash-4.0$ ps -p $$ -F
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
vapier 27999 16493 17 392694 473236 1 18:51 pts/1 00:00:01 bash --norc
that memory never goes away and bash will chew significant CPU (~10%) while it
should be idle ...
-mike
signature.asc
Description: This is a digitally signed message part.