我刚用valgrind来分析我的内存泄漏应用程序,因为我的内存(8 GB)溢出了很长的运行时间。内存使用量随运行时间的增加而增加。
我刚发现此行为可能是有意的: Python memory leaks?
除了产生新进程以防止此行为之外,还有其他方法吗?
我已经尝试过使用python垃圾收集器,但没有成功: How can I explicitly free memory in Python?
我正在使用Python 2.7.3 ...
手动触发垃圾收集:
3,145,728 bytes in 1 blocks are possibly lost in loss record 2,715 of 2,715
==16220== at 0x4C28BED: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16220== by 0x463DA4: ??? (in /usr/bin/python2.7)
==16220== by 0x4A1BB1: PyString_InternInPlace (in /usr/bin/python2.7)
==16220== by 0x4AAED0: ??? (in /usr/bin/python2.7)
==16220== by 0x4AAFD6: ??? (in /usr/bin/python2.7)
==16220== by 0x4AB0C0: ??? (in /usr/bin/python2.7)
==16220== by 0x4AAFD6: ??? (in /usr/bin/python2.7)
==16220== by 0x4AB0C0: ??? (in /usr/bin/python2.7)
==16220== by 0x4AAFD6: ??? (in /usr/bin/python2.7)
==16220== by 0x4AB0C0: ??? (in /usr/bin/python2.7)
==16220== by 0x535AE2: PyMarshal_ReadLastObjectFromFile (in /usr/bin/python2.7)
==16220== by 0x528178: ??? (in /usr/bin/python2.7)
==16220==
==16220== LEAK SUMMARY:
==16220== definitely lost: 456 bytes in 10 blocks
==16220== indirectly lost: 284 bytes in 6 blocks
==16220== possibly lost: 3,844,678 bytes in 1,533 blocks
==16220== still reachable: 16,937,271 bytes in 9,558 blocks
不
==16249== 3,145,728 bytes in 1 blocks are possibly lost in loss record 2,721 of 2,721
==16249== at 0x4C28BED: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16249== by 0x463DA4: ??? (in /usr/bin/python2.7)
==16249== by 0x4A1BB1: PyString_InternInPlace (in /usr/bin/python2.7)
==16249== by 0x4AAED0: ??? (in /usr/bin/python2.7)
==16249== by 0x4AAFD6: ??? (in /usr/bin/python2.7)
==16249== by 0x4AB0C0: ??? (in /usr/bin/python2.7)
==16249== by 0x4AAFD6: ??? (in /usr/bin/python2.7)
==16249== by 0x4AB0C0: ??? (in /usr/bin/python2.7)
==16249== by 0x4AAFD6: ??? (in /usr/bin/python2.7)
==16249== by 0x4AB0C0: ??? (in /usr/bin/python2.7)
==16249== by 0x535AE2: PyMarshal_ReadLastObjectFromFile (in /usr/bin/python2.7)
==16249== by 0x528178: ??? (in /usr/bin/python2.7)
==16249==
==16249== LEAK SUMMARY:
==16249== definitely lost: 456 bytes in 10 blocks
==16249== indirectly lost: 284 bytes in 6 blocks
==16249== possibly lost: 3,844,822 bytes in 1,534 blocks
==16249== still reachable: 16,938,119 bytes in 9,558 blocks
valgrind --tool = massif导致内存使用量增加(see this link for PDF)
答案 0 :(得分:0)
我看到两个可能的解释:
解释器有内存泄漏的可能性,虽然不是不可能的,但远不如上述任何一种。
P.S。就像我喜欢valgrind
一样,我认为它不是一个非常有用的工具,用于精确定位Python程序中的泄漏。