[plug] Does linux have a general garbage collector...

Leon Brooks leonb at bounce.networx.net.au
Wed Dec 22 11:39:01 WST 1999


"Buddrige, David" wrote:
> Was just wondering -- does Linux have a general garbage collector built into
> the kernel such that RAM that was leaked by a badly written C/C++ program
> eventually get's reclaimed despite the RAM not being delete'd in the program
> itself - or would it be lost forever?

Anything not free()'d gets reclaimed when the program dies. AFAIK, none
of the base Linux libraries have inherent leaks (e.g., if I set Apache
subprocesses to serve 5000 requests before doing an elective suicide,
they don't grow at all that I've noticed.

The technique that Apache uses might be useful to you if you have
something closed-source or too large to debug, which leaks. Knock the
task on the head occasionally and spawn a new one (often, you can start
a new server task, which then hangs waiting for a port to listen on,
then kill off the original to release the port; try this in ~/crontab
(all on one line, delete the backslashes), then type "crontab crontab":

    0 * * * * \
    WITH_WEAPON=-KILL \
    OLD_SERVER_PID=$(ps ax|gawk '/:[0-9][0-9] servertaskname/ {print
$1}') \
    start_new_server & \
    sleep 10 & \
    kill $WITH_WEAPON $OLD_SERVER_PID

-- 
Confidence is the feeling you have before you understand the situation.
If at first you don't succeed, try a shorter bungee. When in trouble,
when in doubt, run in circles, scream and shout. The two great secrets
of success are: don't tell anyone everything that you know.


More information about the plug mailing list