02-28-04 10:34 PM
"concern" <conern@somewhere.net> writes:
> Hi all,
>
> On a linux box, there are several instances of my application running for
> different purposes, testing/QA... I also running my own test instance
> "myapp" on it. During working hours, the "size" in top of myapp is easily
> grow and seems no uplimit; after working hour, with same input, the size
> will remain around a certain amount, means:
> on working hours(myapp was a little slower):
> the test client sent 100 requests to myapp, the "size" would grew to 26mb.
> after:
> the test client sent exactly 100 same content(ensure same processing
> routains) request to myapp, size aroud 16mb.
>
> No memleak when checked with valgrind and mtrace() in above 16mb case (the
> 26mb case needs the working day though).
>
> Here goes my questions:
> 1) the size of top constantly grows means a leak?
> 2) if free() of glibc doesn't (always?) return the memory to OS, is this
> behave can be affected by process' current running env or time(how long th
e
> process holds the resource) related?
> 3) what are other possible reasons for above different "size" with same
> inputs/outputs to a process?
Lots of applications have a memory use patterns where
they grow over time, but eventually plateau at some
constant long-term level.
First, note that free() does not return memory to the
OS, only marks that block as free in your process's
heap. Over the long term, free areas in your heap
become intermingled with areas that are in use,
which limits the ability of malloc() to merge small
free blocks into larger blocks. Over time, the heap
becomes more "fragmented", and therefore larger,
until an equilibrium is reached.
Applications that have leaks never reach equilibrium,
but continue to grow indefinitely. Note however that
not every program that grows indefinitely has leaks.
For example, if you allocate memory and store pointers
to those blocks in a list or table, and fail to free
them after they are no longer needed, tools like Purify
(and, I assume, valgrind) won't report them as leaks,
since to all appearances they are still in use.
In rarer cases, a set of memory blocks that contain
circular chains of reference to one another will also
escape detection, since each block will appear to be
used by the other.
-SEan
[ Post a follow-up to this message ]
|