0
我想了解我的應用程序是否泄漏。比較valgrind,地塊,頂部和pmap
當運行我的應用程序,我定期運行pmap
並觀察:
mapped: 488256K writeable/private: 90144K shared: 0K
mapped: 488260K writeable/private: 101912K shared: 0K
mapped: 488256K writeable/private: 102708K shared: 0K
mapped: 488260K writeable/private: 105112K shared: 0K
我跑top
並觀察:
VIRT RES SHR
488260 17684 3020
488256 20060 3032
488256 22700 3032
488256 26132 3032
488256 28772 3032
488256 31880 3032
在 「RES」,並增加 「可寫/私有」什麼讓我懷疑是泄漏。但是,運行valgrind
我並沒有發現任何重大的泄漏,當我中止執行我一直 看到20MB左右可到達的記憶:
==19998==
==19998== HEAP SUMMARY:
==19998== in use at exit: 20,351,513 bytes in 974 blocks
==19998== total heap usage: 329,404 allocs, 328,430 frees, 34,562,346 bytes allocated
==19998==
==19998== LEAK SUMMARY:
==19998== definitely lost: 63 bytes in 4 blocks
==19998== indirectly lost: 0 bytes in 0 blocks
==19998== possibly lost: 4,679 bytes in 76 blocks
==19998== still reachable: 20,346,771 bytes in 894 blocks
==19998== suppressed: 0 bytes in 0 blocks
==19998== Rerun with --leak-check=full to see details of leaked memory
==19998==
==19998== For counts of detected and suppressed errors, rerun with: -v
==19998== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
我跑valgrind --tool=massif
也看到20MB的平:
問題:有人可以解釋爲什麼valgrind和massif告訴我,我的程序一直使用20Mb內存,但top和pmap告訴我用法正在增長嗎?
爲了理解爲什麼'top'顯示增加,你還需要用'valgrind --pages-as-heap = yes'來分析程序中的內存分配。 。你會明白爲什麼會有增加。這是'頂部'測量進程內存消耗的方式。 http://valgrind.org/docs/manual/ms-manual.html#ms-manual.not-measured。並且用'valgrind --pages-as-heap = yes',你會看到在你的程序中這些分配是在哪裏完成的。 – 2014-09-19 05:15:45
感謝哥們,太棒了。至少現在我可以獲得地塊顯示增加..現在我只需要弄清楚如何在我的代碼中追蹤它。 – jsj 2014-09-19 05:24:54