【问题标题】:Memory leaks without allocating any memory没有分配任何内存的内存泄漏
【发布时间】:2013-04-12 22:51:51
【问题描述】:

我只是在测试我正在编写的一些 c 代码,我发现我有很多内存泄漏,所以我想看看它们是从哪里来的。我所有的代码是:

int main() {
    return 0;
}

只是一个没有做任何事情的简单主程序,我遇到了所有这些内存泄漏:

==38882== HEAP SUMMARY:
==38882==     in use at exit: 58,678 bytes in 363 blocks
==38882==   total heap usage: 514 allocs, 151 frees, 62,544 bytes allocated
==38882== 
==38882== LEAK SUMMARY:
==38882==    definitely lost: 8,624 bytes in 14 blocks
==38882==    indirectly lost: 1,168 bytes in 5 blocks
==38882==      possibly lost: 4,925 bytes in 68 blocks
==38882==    still reachable: 43,961 bytes in 276 blocks
==38882==         suppressed: 0 bytes in 0 blocks
==38882== Rerun with --leak-check=full to see details of leaked memory
==38882== 
==38882== For counts of detected and suppressed errors, rerun with: -v
==38882== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

当我在我大学的计算机上运行此代码时,我没有内存泄漏。我的本地机器上是否有什么东西导致了这么多内存泄漏?

【问题讨论】:

  • 您使用的是什么设置?操作系统?编译器?
  • 我正在使用 mac 运行山狮。我正在用 gcc 编译。
  • @KatieCalabro Valgrind 在 OS X 上,尤其是在 Mountain Lion 上非常有问题。你很可能会得到误报。

标签: c memory valgrind


【解决方案1】:

没关系。您的程序使用运行时库(即libc 或等效项),并且该库会根据自己的需要分配一些内存。

【讨论】:

    【解决方案2】:

    我在我的 Mac 上遇到了同样的错误。这要么是 valgrind 问题,要么(更有可能)是 Mac 上的库问题。我建议只在 Linux 上使用 valgrind。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-12
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多