2009-09-13 2 views
7

메모리가 새 것처럼 보이는 파이썬 확장을 작성하고 있습니다. 나는 valgrind를 사용하여 문제의 유물을 알아 내려고 노력하고 있습니다.파이썬 메모리 누수가 있습니까?

그러나 파이썬 자체가 valgrind에 따라 메모리를 새고있는 것으로 보입니다.

hello.py

print "Hello World!" 

과 사람이 strage 동작에 대한 설명이 있습니까

> valgrind --tool=memcheck python ./hello.py 

(...) 
==7937== ERROR SUMMARY: 580 errors from 34 contexts (suppressed: 21 from 1) 
==7937== malloc/free: in use at exit: 721,878 bytes in 190 blocks. 
==7937== malloc/free: 2,436 allocs, 2,246 frees, 1,863,631 bytes allocated. 
==7937== For counts of detected errors, rerun with: -v 
==7937== Use --track-origins=yes to see where uninitialised values come from 
==7937== searching for pointers to 190 not-freed blocks. 
==7937== checked 965,952 bytes. 
==7937== 
==7937== LEAK SUMMARY: 
==7937== definitely lost: 0 bytes in 0 blocks. 
==7937==  possibly lost: 4,612 bytes in 13 blocks. 
==7937== still reachable: 717,266 bytes in 177 blocks. 
==7937==   suppressed: 0 bytes in 0 blocks. 
==7937== Rerun with --leak-check=full to see details of leaked memory. 

을하고 다음 간단한 스크립트를 사용하십니까? 파이썬 인터프리터가 실제로 메모리를 누설하고 있습니까?

python 개발자는 메모리 누수를 디버깅하기 위해 어떤 도구를 사용합니까?

답변

12

파이썬 Valgrind의를 사용하려고 여러 가지주의 사항을 설명 파이썬 소스에서 전체 README.valgrind있다 :

http://svn.python.org/projects/python/trunk/Misc/README.valgrind

Python uses its own small-object allocation scheme on top of malloc, 
called PyMalloc. 

Valgrind may show some unexpected results when PyMalloc is used. 
Starting with Python 2.3, PyMalloc is used by default. You can disable 
PyMalloc when configuring python by adding the --without-pymalloc option. 
If you disable PyMalloc, most of the information in this document and 
the supplied suppressions file will not be useful. As discussed above, 
disabling PyMalloc can catch more problems. 

If you use valgrind on a default build of Python, you will see 
many errors like: 

     ==6399== Use of uninitialised value of size 4 
     ==6399== at 0x4A9BDE7E: PyObject_Free (obmalloc.c:711) 
     ==6399== by 0x4A9B8198: dictresize (dictobject.c:477) 

These are expected and not a problem. 
2

누수는 파이썬이 아닌 자신의 확장자에서 발생할 가능성이 큽니다. 대용량 시스템은 프로세스가 거의 끝나면 명시 적으로 해제할만한 가치가 없기 때문에 메모리가 할당 된 상태에서 종료됩니다.