简体   繁体   English

C ++代码内存泄漏

[英]C++ code memory leak

I have C++ code executing on a ARM CPU hardware under Linux. 我在Linux下的ARM CPU硬件上执行C ++代码。 I run my binary o the hardware and keep monitoring my process to see if its memory usage is growing over time, every half hour interval. 我在硬件上运行我的二进制文件并继续监视我的进程,看看它的内存使用量是否每隔半小时间隔就会增长。

top -p pid-of-process

to see columns: RES memory and mem % in top output 查看列:顶部输出中的RES内存和mem%

and also check 并检查

cat /proc/pid-of-process/status 

to see field VMRSS : which is Resident Set size memory of my process. 查看字段VMRSS :这是我的进程的驻留集大小内存。

I see that VMRSS and RES memory keeps increasing by some hundreds of KiloBytes every 1 hour. 我看到VMRSS和RES内存每1小时增加几百KiloBytes。 the process is just running, no tests are running so its doing same thing all the time, and load does not vary. 这个过程刚刚运行,没有测试正在运行所以它一直在做同样的事情,负载不会变化。

Now Question I have is: Does this mean there is a possible memory leak in my code. 现在问题是:这是否意味着我的代码中可能存在内存泄漏。

or could this increase be attributed to something else, if any? 或者这种增加是否可归因于其他东西,如果有的话?

To check if there is memory leak: 要检查是否存在内存泄漏:

  1. I reviewed code to see every new(dynamic memory operator) had a corresponding delete (free memory) 我查看了代码,看到每个新的(动态内存运算符)都有相应的删除(可用内存)

  2. Ran the whole process on valgrind memcheck, and in the report did not see any leaks. 在valgrind memcheck上完成整个过程,并在报告中没有看到任何泄漏。 I see 我懂了

definitely lost: 0 bytes in 0 blocks 绝对丢失:0个块中的0个字节

indirectly lost: 0 bytes in 0 blocks 间接丢失:0个块中的0个字节

possibly lost: 1,008 bytes in 7 blocks 可能丢失:7个块中的1,008个字节

* *EDIT: To answer arne's comment below. * *编辑:回答下面的arne评论。 The possibly lost blocks are from pthread_create and onwards glibc, so not sure how is that/what is going on? 可能丢失的块来自pthread_create和glibc,所以不确定那是怎么回事?

720 bytes in 5 blocks are possibly lost in loss record 27 of 56 5个块中的720个字节可能在56的丢失记录27中丢失

==11151== at 0x402732C: calloc (vg_replace_malloc.c:467) == 11151 ==在0x402732C:calloc(vg_replace_malloc.c:467)

==11151== by 0x4010C34: allocate_dtv (dl-tls.c:300) == 11151 == by 0x4010C34:allocate_dtv(dl-tls.c:300)

==11151== by 0x40113D8: _dl_allocate_tls (dl-tls.c:464) == 11151 == by 0x40113D8:_dl_allocate_tls(dl-tls.c:464)

==11151== by 0x404746C: pthread_create@@GLIBC_2.1 (allocatestack.c:571)** == 11151 == by 0x404746C:pthread_create @@ GLIBC_2.1(allocatestack.c:571)**

What could this increase in memory over time be? 随着时间的推移,内存会增加多少? How could I debug further to find the cause? 我怎么能进一步调试才能找到原因?

Since you can't find a straightforward leak, you seem to need to compare snapshots of memory state to see what has changed. 由于您无法找到直接泄漏,因此您似乎需要比较内存状态的快照以查看已更改的内容。 A quick search indicates that valgrind's massif can do snapshots, and there's a python script to compare them (but probably you can compare by hand if your program is small) 快速搜索表明valgrind的massif可以做快照,并且有一个python脚本来比较它们(但如果你的程序很小,你可以用手比较)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM