Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect memory leak with htop

folks, i created an application which consist of GTK+ library and some linked-list on it

and when i see the resources through htop it showed up like these :

    1  [||||||||||||||||||||||                                                             24.4%]     Tasks: 117, 163 thr; 1 running
  2  [||||||||||||||||||||                                                               21.8%]     Load average: 0.22 5.09 7.51 
  Mem[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||               330/2003MB]     Uptime: 6 days, 02:09:22
  Swp[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  220/254MB]

  PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
 1843 rahulyud  20   0 94496  9296  5596 S 17.0  0.5  0:57.59 gnome-terminal
 1118 root      20   0 41112  8556  2612 S 14.0  0.4 25h13:05 /usr/bin/X :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-ubcbQV/database -nolisten tcp vt7
 3035 root      20   0  2808  1468  1056 R  5.0  0.1  0:11.30 htop
 1563 rahulyud  20   0  265M 19400  6792 S  4.0  0.9 12h17:58 compiz
 2594 rahulyud  20   0  373M 25064 10316 S  1.0  1.2  0:13.75 /home/rahulyudi/NetBeansProjects/mm/trunk/dist/Debug/GNU-Linux-x86/trunk

unfortunately, im not really familiar with unix htop-things, my app run with pid 2594, but it seems appears that VIRT cost resources too high -> 373M, thought it was 373 megabytes, am i right ? anyway is that size normal ?

what really VIRT,RES,SHR mean ? how to detect that my app memory resources by these symbol ?

thank in advance ;)

like image 806
capede Avatar asked May 17 '11 19:05

capede


2 Answers

That isn't the ps command. It is the top or htop command. Do you have an alias set?

The VIRT column is all virtual memory and page files associated with the task, including libraries, and memory allocated but not used. RES is the physical memory currently in use. SHR is the memory that could be shared with other processes, such as shared libraries.

For more information or detail on these commands type:

man top

At your terminal. Then you can use / to search for your text.

EDIT:

Just a quick heads up for anyone who comes across this later, I found a program on freshmeat called memtime, which allows you to see the memory used for a command you run. That would solve your problem, without needing to manually watch the program with htop.

like image 110
Spencer Rathbun Avatar answered Sep 28 '22 06:09

Spencer Rathbun


VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment. RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.

SHR indicates how much of the VIRT size is actually sharable memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.

like image 25
SimonZC Avatar answered Sep 28 '22 05:09

SimonZC