4

我从 Valgrind 得到这个结果:

    ==24810== HEAP SUMMARY:
    ==24810==     in use at exit: 0 bytes in 0 blocks
    ==24810==   total heap usage: 9 allocs, 6 frees, 0 bytes allocated
    ==24810== 
    ==24810== LEAK SUMMARY:
    ==24810==    definitely lost: 0 bytes in 0 blocks
    ==24810==    indirectly lost: 0 bytes in 0 blocks
    ==24810==      possibly lost: 0 bytes in 0 blocks
    ==24810==    still reachable: 0 bytes in 0 blocks
    ==24810==         suppressed: 0 bytes in 0 blocks

它说没有内存泄漏。在我看来这是一个很好的结果。但是,这9 个分配,6 个释放呢?看起来我还没有在某处释放一些内存。我检查了代码,有 3 个全局 const 指针。也许它们不被视为错误,而是被打印为未释放?

我应该担心这个还是应该认为代码没有错误?谢谢你们。....只是试图理解指针和内存分配的所有 ANSI C 麻烦:)))

格言

4

1 回答 1

0

in valgrind website http://valgrind.org/docs/manual/quick-start.html#quick-start.interpret

"definitely lost": your program is leaking memory -- fix it!

"probably lost": your program is leaking memory, unless you're doing funny things with pointers (such as moving them to point to the middle of a heap block).

So for your case your program should be good.

于 2012-12-12T23:30:07.733 回答