[NBLUG/talk] memory leak question

Kyle Rankin kyle at nblug.org
Sun Mar 16 10:43:01 PDT 2008

On Sun, Mar 16, 2008 at 10:19:37AM -0700, Sean wrote:
> I suspect I might be having a memory leak problem, but I don't know
> how to check for it properly.
> As time goes on, more and more RAM gets used up, until the swappage
> gets to bad that the computer is too sluggish to use. I suspect it
> even causes my system to freeze up periodically.
> According to top, only a small portion (roughly 28%) of my RAM is
> used, but according to free about 75% is used. If a memory leak is
> taking place, I presume that top won't accurately show how much the
> said process is using? Is there a way, say a program I don't know
> about, that will help me track this?
> I've been suspecting this has been happening for awhile, and a recent
> dist-upgrade does not seem to have fixed the problem. It is probably
> happening on both my Debian Etch boxes, one 64-bit the other 32-bit. I
> do have some non-repository software installed (from tar) on both, so
> the upgrade may not have solved the problem. The main software common
> to both of them is vmware-server (free).
> Is there a way to track the memory leak, if any, or at least find out
> who the culprit is?
> Thank you for your help.
> Sean

When you check free, be sure you take the Linux file cache into account. I
don't know whether you already know about the file cache or not, but for the
benefit of members of this list that don't I'll act as though you don't, so
bear with me.  For instance, how would you read this?

greenfly at minimus:~$ free
             total       used       free     shared    buffers     cached
Mem:       1026288    1002648      23640          0       5820     447888
-/+ buffers/cache:     548940     477348
Swap:      1052216      34776    1017440

It might look like I've used almost all of my 1Gb of RAM on this system
according to the used column, but look at the far right to the cached
column. It shows that I have 447Mb cached. When you open files, if Linux
has spare RAM, it actually caches some of those open files into memory. The
idea is, if you have RAM to spare, the next time you open the file, it will
open much faster since it's already in RAM.

Because of this, at first glance basically all Linux systems will appear to
be consuming all available RAM after the system has been up for awhile. The
best way to check the actual used RAM is to skip down to to the -/+
buffers/cache. If you look there you'll see that I have 548940Kb actually
in use, and 477348Kb free.

Now, if you do have an application with a memory leak (Firefox and pidgin
have been a culprit in the past) top should show that over time it
continues to consume more and more RAM, but when you restart the
application it uses a substantial amount less. Now apps do often need more
RAM as they are running (ie. for Firefox it needs more RAM for each tab you
open) so it can be somewhat difficult to identify memory leaks sometimes.

Hope this helps,

Kyle Rankin
NBLUG President
The North Bay Linux Users Group
IRC: greenfly at irc.freenode.net #nblug 
kyle at nblug.org

More information about the talk mailing list