免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2235 | 回复: 2
打印 上一主题 下一主题

valgrind 发现的内存泄漏问题,请人帮解一下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-09-02 11:41 |只看该作者 |倒序浏览
  1. int main()
  2. {  
  3.         //sigset_t sign;
  4.         //sigemptyset(&sign);
  5.         //sigaddset(&sign, SIGINT);
  6.         //sigprocmask(SIG_SETMASK,&sign,NULL);
  7.         //struct sigaction siga;
  8.         //siga.sa_handler = SIG_DFL;
  9.         //siga.sa_mask = sign;
  10.         //siga.sa_flags = SA_ONESHOT|SA_NOMASK;
  11.         //siga.sa_restorer = NULL;
  12.         //sigaction(SIGINT, &siga, NULL);

  13.         //Timer::initTimer();
  14.         trace tr;
  15.         trace2 tr2;
  16.         //Timer::getSingletionPtr()->setTimer(1,SubscriberHelper(&tr, &trace::output),5);
  17.         //Timer::getSingletionPtr()->setTimer(2,SubscriberHelper(&tr2, &trace2::output2),1);
  18.         //sleep(10);
  19.         //Timer::releaseTimer();
  20.         std::map<int,int> mymap;
  21.         mymap.insert(std::make_pair(3,3));
  22.         mymap.clear();
  23.         return 0;
  24. }
复制代码
代码如上, 用valgrind 做内存泄漏测试时如果如下
valgrind --tool=memcheck --leak-check=full  --show-reachable=yes ./testApp

==20974== 960 bytes in 1 blocks are still reachable in loss record 1 of 1
==20974==    at 0x4004790: operator new(unsigned) (vg_replace_malloc.c:164)
==20974==    by 0x40E9BA0: std::__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned, int& (in /usr/lib/libstdc++.so.5.0.7)
==20974==    by 0x40E9AAC: std::__default_alloc_template<true, 0>::_S_refill(unsigned) (in /usr/lib/libstdc++.so.5.0.7)
==20974==    by 0x40E9687: std::__default_alloc_template<true, 0>::allocate(unsigned) (in /usr/lib/libstdc++.so.5.0.7)
==20974==    by 0x804931B: std::__simple_alloc<std::_Rb_tree_node<std::pair<int const, int> >, std::__default_alloc_template<true, 0> >::allocate(unsigned) (stl_alloc.h:23
==20974==    by 0x80491EF: std::_Rb_tree_alloc_base<std::pair<int const, int>, std::allocator<std::pair<int const, int> >, true>::_M_get_node() (stl_tree.h:564)
==20974==    by 0x8048E01: std::_Rb_tree_base<std::pair<int const, int>, std::allocator<std::pair<int const, int> > >::_Rb_tree_base(std::allocator<std::pair<int const, int> > const& (stl_tree.h:579)
==20974==    by 0x8048B1C: std::_Rb_tree<int, std::pair<int const, int>, std::_Select1st<std::pair<int const, int> >, std::less<int>, std::allocator<std::pair<int const, int> > >::_Rb_tree(std::less<int> const&, std::allocator<std::pair<int const, int> > const& (stl_tree.h:730)
==20974==    by 0x8048A3E: std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::map() (stl_map.h:124)
==20974==    by 0x8048988: main (main.cpp:52)
==20974==
==20974== LEAK SUMMARY:
==20974==    definitely lost: 0 bytes in 0 blocks.
==20974==      possibly lost: 0 bytes in 0 blocks.
==20974==    still reachable: 960 bytes in 1 blocks.
==20974==         suppressed: 0 bytes in 0 blocks.

这里的 still reachable 的960字节是代表泄漏吗?

论坛徽章:
0
2 [报告]
发表于 2010-09-02 12:24 |只看该作者
那个960字节不是内存泄漏,这是由C++统一管理的。

论坛徽章:
0
3 [报告]
发表于 2010-09-02 13:11 |只看该作者
哦, 谢谢.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP