Detecting Memory Leaks

Robert L Krawitz rlk at alum.mit.edu
Fri Jul 16 10:03:01 EDT 2004


   From: Jerry Feldman <gaf at blu.org>
   Date: Fri, 16 Jul 2004 07:30:19 -0400

   On Thu, 15 Jul 2004 18:04:00 -0400
   Josh Pollak <pardsbane at offthehill.org> wrote:

   > As someone else said on this list, its possible you don't have a
   > memory leak, but rather the program is allocating memory and just not 
   > deallocating it until much later. Also, as they said the memory might 
   > not be returned to the OS just because you deallocated it. 

   Most allocators never return memory back to the OS, and I am sure that
   this is true with glibc. 

I think glibc does, at least on Linux -- I've seen process sizes
shrink as well as grow.  However, it can only return full pages back
to the OS.  So if your application is fragmenting its heap, it may
become less and less able to return pages like this, even if it's not
actually leaking memory.

It's also possible that the application genuinely uses more memory
over time, without technically leaking memory.  A memory leak,
technically speaking, refers to memory which is not freed, but to
which there are no pointers (so that it cannot be accessed).  For
example, if it maintains a linked list to which it adds elements over
time, it wouldn't show up as a leak even though the process size would
be growing over time.

-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

Tall Clubs International  --  http://www.tall.org/ or 1-888-IM-TALL-2
Member of the League for Programming Freedom -- mail lpf at uunet.uu.net
Project lead for Gimp Print   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton



More information about the Discuss mailing list