in reply to Re: Memory leak when using hash 'references'
in thread Memory leak when using hash 'references'

I am not a guru on OSes but I didn't think that was the case, or services like ftp, apache and mysql could consume a system within hours. I wrote a very simple c++ program:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> void main (void ) { int *a[10000]; long c = 0; do { a[c] = new int[1000] ; } while ( c++ < 10001 ); c = 0; do { delete a[c]; } while ( c++ < 10001 ); sleep( 20 ); }
the above program gives back the memory to the system, and top shows no abnormal memory usage. Removing the second loop results in an approxmiately 40MB memory usage.

I tested this on Redhat 7.3 (2.4.18-3) gcc version 2.96 20000731

edited: Mon May 5 14:02:53 2003 by jeffa - code tags

Replies are listed 'Best First'.
Re: Re: Re: Memory leak when using hash 'references'
by Tanalis (Curate) on May 05, 2003 at 05:49 UTC
    services like ftp, apache and mysql could consume a system within hours

    Don't each of those re-exec themselves every time a request is made to them to stop that from happening? The way I understand it, an incoming request uses the existing server, and a second, new server process is forked off to await the next request. That initial process is then free to exit once the request is complete, releasing any resources it was holding. Admittedly, my OS knowledge is fairly basic (stuff from Uni, and from my own personal interest), but I'm sure I've read that somewhere *grins*.

    the above program gives back the memory to the system, and top shows no abnormal memory usage

    Gives memory back to the system how? Can you provide some specifics (numeric data as to what's going on, including the name of the field you're looking at in top?) A loop wouldn't (necessarily) use a large amount of memory in its own right; it'd be interesting to get a better idea of what's going on.

    -- Foxcub
    A friend is someone who can see straight through you, yet still enjoy the view. (Anon)