仍然可以在valgrind [英] Still reachable in valgrind

查看:210
本文介绍了仍然可以在valgrind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索关于valgrind中仍然可以访问的时候,有些人说这不是问题。我们不用nedd来解决它。有人说它需要修正,如果有人能明确地告诉我这个还可以达到的逻辑是什么,会更好一些。是否有必要解决这个问题?





我的C程序有以下valgrind输出。我需要解决它吗?

  LEAK SUMMARY:
== 27333 ==绝对丢失:0字节在0块。
== 27333 ==可能丢失:0个字节在0个块中。
== 27333 ==仍然可达:96个字节在12个块。
== 27333 == suppress:0个字节,0个块。


解决方案

仍然可达意味着你在退出之前还没有释放内存块,而是指向它。



在C ++程序中,这意味着某些对象可能有不是删除 d,因此它的析构函数可能没有被运行,因此说一些数据可能没有被保存到磁盘上,例如一些其他动作可能没有被采用因此您的程序可能会产生意外的行为。



然而,C程序中没有析构函数,所以你的程序不能依赖于这个。还要释放内存需要一些时间,所以在退出时不要释放内存,你可以节省一些时间 - 你的程序将退出更快(这对于有大量数据的程序来说可能会很重要)。



因此,如果您的C程序具有仍然可达的块,那么它不是问题,但这表示程序中的某些代码不会释放内存,因此您可以在重用该代码时期望出现错误。


While searching about still reachable in valgrind, some people say its not a problem. we don't nedd to fix it. Some people say it needs to be fixed.I would be better if somebody could exaplain me explicitly what is the logic behind this still reachable. Is it mandatory to fix this?

[EDIT]

I have following valgrind output for my C program.Do i need to fix it?

      LEAK SUMMARY:
      ==27333==    definitely lost: 0 bytes in 0 blocks.
      ==27333==      possibly lost: 0 bytes in 0 blocks.
      ==27333==    still reachable: 96 bytes in 12 blocks.
      ==27333==         suppressed: 0 bytes in 0 blocks.

解决方案

It depends. "Still reachable" means you haven't deallocated a block of memory before exiting, but had a pointer to it.

In a C++ program this means that some object could have not been deleted and therefore its destructor might not have been run and thus say some data might have not been saved onto disk for example and some other action might not have been taken and thus your program might produce unexpected behavior.

However there're no destructors in C programs, so your program just can't depend on that. Also deallocating memory takes some time, so by not freeing memory on exit you can save some time - your program will exit faster (this can be significant for programs with lots of data).

So IMO if your C program has "still reachable" blocks it's not a problem but this indicates that some code in the program doesn't free memory and so you can expect bugs when reusing that code.

这篇关于仍然可以在valgrind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆