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

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

问题描述

虽然在 valgrind 中搜索仍然可达,但有人说这不是问题.我们不需要修复它.有人说它需要修复.如果有人能明确解释我这背后的逻辑是什么,我会更好.是否必须修复此问题?

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?

我的 C 程序有以下 valgrind 输出.我需要修复它吗?

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.

在 C++ 程序中,这意味着某些对象可能没有被deleted,因此它的析构函数可能没有运行,因此说一些数据可能没有保存到磁盘上,例如可能尚未采取其他操作,因此您的程序可能会产生意外行为.

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.

但是在 C 程序中没有析构函数,所以你的程序不能依赖它.释放内存也需要一些时间,因此通过在退出时不释放内存,您可以节省一些时间 - 您的程序将退出得更快(这对于具有大量数据的程序来说意义重大).

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).

因此,如果您的 C 程序具有仍然可访问"的块,那么 IMO 不是问题,但这表明程序中的某些代码没有释放内存,因此您在重用该代码时可能会出现错误.

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天全站免登陆