Detect memory leak with htop

folks, I created an application consisting of a GTK + library and some linked list on it

and when I see the resources via htop , it looks like this:

  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, they are not very familiar with unix htop -things, my application works with pid 2594, but it seems that VIRT too high resource resources β†’ 373M, thought it was 373 megabytes , am I right? Anyway, is this size normal?

What does VIRT , RES , SHR really mean? How to determine what my application memory resources are using these characters?

Thank you in advance;)

+4
source share
3 answers

This is not a ps command. This is a top or htop command. Do you have a set of aliases?

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

For more information or details about these commands, enter:

man top

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

EDIT:

Just get up quickly for anyone who comes across this later, I found a program on freshmeat called memtime that allows you to see the memory used for the command you are running. This will solve your problem without having to manually watch the program using htop.

+6
source

Memory leaks, by definition, cannot be detected by a single snapshot. When you leak memory, your process uses more memory over time. While the virtual 373M may seem high, if you do not get more and more memory, if the application does nothing that should increase its memory usage, you cannot say that you have a leak. If you suspect you have a leak, you might want to examine Valgrind .

+2
source

VIRT means the virtual size of the process, which is the sum of the memory that it actually uses, the memory that it mapped into itself (for example, the video card RAM for the X server), the files on the disk that were mapped (in particular shared libraries), and memory shared by other processes. VIRT represents how much memory the program currently has access to. RES means the size of the resident, which is an accurate representation of how much actual physical memory is consumed by the process. (This also directly matches the% MEM column.) It will almost always be smaller than the VIRT size, since most programs depend on the C library.

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

+2
source

All Articles