内存泄漏而不分配任何内存

时间:2013-04-12 22:51:51

标签: c memory valgrind

我刚刚测试了一些我写的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)

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我在Mac上遇到同样的错误。它可能是一个valgrind问题,或者(很可能)是Mac上的库问题。我建议只在Linux上使用valgrind。