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

Buddrige, David david.buddrige at mitswa.com.au
Wed Dec 22 11:47:23 WST 1999


Thanks heaps everybody for your replies - it's been something that I've been
curious about for a while.  As a programmer, my programs (while still in
development) may have the odd memory leak, and was wondering if the ram that
gets lost can be reclaimed by the system without a reboot - for example, if
I do several test runs on a program that is still leaking memory, will I
eventually use up the system's RAM - forcing a reboot.  This answers
basically tell me that this is not a problem for linux (or unix in general).
Anyone know if it is a problem for an operating system originating in
Redmond (my gut instincts suggest it is highly likely - but I have no firm
evidence on that)

thanks heaps all.. 8-)

David Buddrige

-----Original Message-----
From: Leon Brooks [mailto:leonb at bounce.networx.net.au]
Sent: Wednesday, 22 December 1999 11:39
To: Perth Linux Users Group
Subject: Re: [plug] Does linux have a general garbage collector...


"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