内存泄露bug指南(二)
2013-05-09 14:40
1081 查看
[root@s144 src]# env HEAPCHECK=normal /root/src/test_memleak
WARNING: Perftools heap leak checker is active -- Performance may suffer
An error occurred.Skipping final stage
Leak check _main_ detected leaks of 404 bytes in 1 objects
The 1 largest leaks:
Using local file /root/src/test_memleak.
Leak of 404 bytes in 1 objects allocated from:
@ 4007ff main
@ 3d8dc1d994 __libc_start_main
If the preceding stack traces are not enough to find the leaks, try running THIS shell command:
pprof /root/src/test_memleak "/tmp/test_memleak.25383._main_-end.heap" --inuse_objects --lines --heapcheck --edgefraction=1e-10 --nodefraction=1e-10 --gv
If you are still puzzled about why the leaks are there, try rerunning this program with HEAP_CHECK_TEST_POINTER_ALIGNMENT=1 and/or with HEAP_CHECK_MAX_POINTER_OFFSET=-1
If the leak report occurs in a small fraction of runs, try running with TCMALLOC_MAX_FREE_QUEUE_SIZE of few hundred MB or with TCMALLOC_RECLAIM_MEMORY=false, it might help fi
Exiting with error code (instead of crashing) because of whole-program memory leaks
上面的报告显示有404个字节的内存泄漏,并提示使用pprof进一步跟踪泄漏来源的方法。
[root@s144 src]# pprof /root/src/test_memleak "/tmp/test_memleak.25383._main_-end.heap" --inuse_objects --lines --heapcheck --edgefraction=1e-10 --nodefraction=1e-10 --text
Using local file /root/src/test_memleak.
Using local file /tmp/test_memleak.25383._main_-end.heap.
Total: 1 objects
1 100.0% 100.0% 1 100.0% main /root/src/test_memleak.cpp:14
0 0.0% 100.0% 1 100.0% __libc_start_main ??:0
根据上面提示,锁定具体的代码文件及代码行,协助开发快速定位到内存泄露问题bug。当然这是很简单的例子,还得经得起实际应用程序的考验,帮助开发成长避免重复错误,拿饮食行业比喻,想成为美食评估师,而不是清洁服务员。
最后,补充一点,除了前面使用env命令行的全局内存泄漏检查方式外,还可以作对代码段的更加细粒度的泄漏检查。这里考虑不修改源代码的前提下检查内存泄露,所以暂时不考虑。好的 C/C++程序员,应该做到自己的程序都能优雅退出,这是最基本的要求。这里所谓的优雅退出,指的是退出的时候把该释放的资源释放掉,且保证程序退出时不挂。
WARNING: Perftools heap leak checker is active -- Performance may suffer
An error occurred.Skipping final stage
Leak check _main_ detected leaks of 404 bytes in 1 objects
The 1 largest leaks:
Using local file /root/src/test_memleak.
Leak of 404 bytes in 1 objects allocated from:
@ 4007ff main
@ 3d8dc1d994 __libc_start_main
If the preceding stack traces are not enough to find the leaks, try running THIS shell command:
pprof /root/src/test_memleak "/tmp/test_memleak.25383._main_-end.heap" --inuse_objects --lines --heapcheck --edgefraction=1e-10 --nodefraction=1e-10 --gv
If you are still puzzled about why the leaks are there, try rerunning this program with HEAP_CHECK_TEST_POINTER_ALIGNMENT=1 and/or with HEAP_CHECK_MAX_POINTER_OFFSET=-1
If the leak report occurs in a small fraction of runs, try running with TCMALLOC_MAX_FREE_QUEUE_SIZE of few hundred MB or with TCMALLOC_RECLAIM_MEMORY=false, it might help fi
Exiting with error code (instead of crashing) because of whole-program memory leaks
上面的报告显示有404个字节的内存泄漏,并提示使用pprof进一步跟踪泄漏来源的方法。
[root@s144 src]# pprof /root/src/test_memleak "/tmp/test_memleak.25383._main_-end.heap" --inuse_objects --lines --heapcheck --edgefraction=1e-10 --nodefraction=1e-10 --text
Using local file /root/src/test_memleak.
Using local file /tmp/test_memleak.25383._main_-end.heap.
Total: 1 objects
1 100.0% 100.0% 1 100.0% main /root/src/test_memleak.cpp:14
0 0.0% 100.0% 1 100.0% __libc_start_main ??:0
根据上面提示,锁定具体的代码文件及代码行,协助开发快速定位到内存泄露问题bug。当然这是很简单的例子,还得经得起实际应用程序的考验,帮助开发成长避免重复错误,拿饮食行业比喻,想成为美食评估师,而不是清洁服务员。
最后,补充一点,除了前面使用env命令行的全局内存泄漏检查方式外,还可以作对代码段的更加细粒度的泄漏检查。这里考虑不修改源代码的前提下检查内存泄露,所以暂时不考虑。好的 C/C++程序员,应该做到自己的程序都能优雅退出,这是最基本的要求。这里所谓的优雅退出,指的是退出的时候把该释放的资源释放掉,且保证程序退出时不挂。
相关文章推荐
- 内存泄露bug指南(一)
- Instruments指南:如何调试内存泄露
- 充满BUG的世界观——再遇Java内存泄露
- appium的一个内存泄露bug
- dbcp 1.4 底层连接断开时内存泄露bug
- 好用的BUG、内存泄露捕捉工具 EurekaLog v6.0.11 Enterprise For D5-D2007 简体中文汉化版
- 好用的BUG、内存泄露捕捉工具 EurekaLog v6.0.11 Enterprise For D5-D2007 简体中文汉化版
- linux下内存泄露查找、BUG调试
- 解Bug之路:记一次JVM堆外内存泄露Bug的查找
- Android融云使用不当产生的内存泄露和BUG(匿名类回调导致Activity内存泄露)
- Memcached 二进制协议(BinaryProtocol) incr指令泄露内存数据的bug
- Visual Studio 2010 STL的一个bug导致内存泄露
- bug--内存泄露
- [心得]brew程序中泄露内存的bug
- Android开发笔记——常见BUG类型之内存泄露与线程安全
- Visual Studio 2010 STL的一个bug导致内存泄露
- 好用的BUG、内存泄露捕捉工具 EurekaLog v6.0.3 Enterprise For D5-D2007
- Visual Studio 2010 STL的一个bug导致内存泄露
- <转载>linux下内存泄露查找、BUG调试
- Android开发笔记——常见BUG类型之内存泄露与线程安全