使用 htop 检测内存泄漏
伙计们,我创建了一个由 GTK+ 库和其中的一些链接列表组成的应用程序
,当我通过 htop
查看资源时,它显示如下:
1 [
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 [
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(20)
|| 24.4%] Tasks: 117, 163 thr; 1 running
2 [
|| 24.4%] Tasks: 117, 163 thr; 1 running
2 [
21.8%] Load average: 0.22 5.09 7.51
Mem[
21.8%] Load average: 0.22 5.09 7.51
Mem[
||| 330/2003MB] Uptime: 6 days, 02:09:22
Swp[
||| 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
不幸的是,我不太熟悉 unix
htop
-things,我的应用程序以 pid 2594 运行,但似乎
VIRT
成本资源太高 -> 373M,以为是373兆,对吗?无论如何,这个尺寸正常吗?VIRT
、RES
、SHR
到底是什么意思?如何通过这些符号检测我的应用程序内存资源?
预先感谢;)
||||||| 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 ;)
这不是 ps 命令。它是 top 或 htop 命令。您有别名集吗?
VIRT 列是与任务关联的所有虚拟内存和页面文件,包括库和已分配但未使用的内存。 RES 是当前正在使用的物理内存。 SHR 是可以与其他进程共享的内存,例如共享库。
有关这些命令的更多信息或详细信息,请键入:
在你的终端。然后您可以使用 / 来搜索您的文本。
编辑:
对于后来遇到这个问题的人来说,请注意,我在 freshmeat 上发现了一个名为 memtime 的程序,它允许您查看您运行的命令所使用的内存。这将解决您的问题,而无需使用 htop 手动观看节目。
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:
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.
VIRT 代表进程的虚拟大小,它是它实际使用的内存、它映射到自身的内存(例如 X 服务器的显卡 RAM)、磁盘上已映射到它的文件的总和(最值得注意的是共享库),以及与其他进程共享的内存。 VIRT 表示程序当前能够访问多少内存。 RES 代表驻留大小,它准确表示进程实际消耗了多少物理内存。 (这也直接对应于 %MEM 列。)这实际上总是小于 VIRT 大小,因为大多数程序都依赖于 C 库。
SHR 表示 VIRT 大小中有多少实际上是可共享内存或库)。就图书馆而言,这并不一定意味着整个图书馆都是常驻的。例如,如果程序仅使用库中的几个函数,则整个库都会被映射并计入 VIRT 和 SHR,但实际上只有库文件中包含正在使用的函数的部分才会被加载并计入其中根据RES。
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.
根据定义,内存泄漏不能通过一个快照来暴露。当您泄漏内存时,您的进程会随着时间的推移使用更多的内存。虽然 373M 虚拟可能看起来很高,但除非您获得越来越多的内存,而应用程序没有执行任何会增加其内存使用量的操作,否则您不能说存在泄漏。如果您怀疑存在泄漏,您可能需要使用 Valgrind 进行调查。
Memory leaks by definition cannot be exposed by one snapshot. When you leak memory, your process uses more memory over time. While 373M virtual may seem high, unless you gain more and more memory without the application doing anything that should increase it's memory usage you cannot say you have a leak. If you suspect you have a leak you may want to look into using Valgrind.