Valgrind在一个简单的C程序上的结果

时间:2016-02-21 17:38:04

标签: c valgrind

我刚刚开始试用Valgrind,作为一个控件,我在一个简单的C文件上运行它并得到了意想不到的结果。以下是blank.c

的内容
int main() {
  return 0;
}

我使用gcc -o blank blank.c

编译

我跑了valgrind --tool=memcheck ./blank并得到了这个输出:

==7877== Memcheck, a memory error detector
==7877== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7877== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==7877== Command: ./blank
==7877== 
==7877== 
==7877== HEAP SUMMARY:
==7877==     in use at exit: 22,177 bytes in 185 blocks
==7877==   total heap usage: 267 allocs, 82 frees, 28,377 bytes allocated
==7877== 
==7877== LEAK SUMMARY:
==7877==    definitely lost: 0 bytes in 0 blocks
==7877==    indirectly lost: 0 bytes in 0 blocks
==7877==      possibly lost: 0 bytes in 0 blocks
==7877==    still reachable: 0 bytes in 0 blocks
==7877==         suppressed: 22,177 bytes in 185 blocks
==7877== 
==7877== For counts of detected and suppressed errors, rerun with: -v
==7877== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

我不明白为什么Heap Summary显示使用的内存如此之多以及当我的程序没有做任何事情时会有如此多的alloc。我如何理解/解决这个问题?

我不确定其他哪些信息会有所帮助,但gcc --version会返回

Configured with: --  prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix

---编辑--- 就像这个重复的另一个问题一样,如果我在Linux机器上运行我的琐碎的C程序,一切看起来都很干净漂亮。

0 个答案:

没有答案