[OCLUG-devel] Memory Leaks

Christopher Smith x at xman.org
Wed May 25 23:04:20 PDT 2005


James Colannino wrote:

>Hey everyone.  I have a more abstract question about what happens during
>a memory leak.  I know that a program "leaks memory" when it
>continuously allocates more RAM without freeing it.  My question is,
>what happens when the process terminates?  Does the leak only effect the
>system while the process is running, or is the memory permanently lost
>until the next reboot?  The thing that brought this up was that I was
>reading a couple days ago in my C book about memory leaks.  I guess this
>would probably be a good time for me to learn about how Linux manages
>memory.
>  
>
In a POSIX system (and actually it's true in Windows and basically 
anything that has "real" processes), a process gets it's own set of 
memory along with other resources. When that process dies, those 
resources are all released and reclaimed by the kernel. That's basically 
one of the key jobs of the kernel. So a memory leak in your program 
won't last past the life of said program.

There are, as always, exceptions. ;-) First, if there is a bug in the 
kernel, you could have a memory leak that won't get fixed until you 
reboot. Secondly, things like Sys V shared memory aren't owned by any 
one process, so the kernel can't know whether to free them if a 
particular process dies.

Modern Operating Systems (now Distributed Operating Systems I think) by 
Tanenbaum (yes, *that* Tanenbaum) did a good job of explaining how 
operating systems do this.

--Chris


More information about the OCLUG-devel mailing list