2009-09-13 15 views
7

Piszę rozszerzenie python, który wydaje się być wyciekającej pamięci. Próbuję dowiedzieć się, jaki jest problem z użyciem valgrind.Wycieki pamięci Pythona?

Jednak wygląda na to, że pyton sam przecieka pamięć zgodnie z wartością valgrind. Stosując następujący prosty skrypt:

hello.py

print "Hello World!" 

i robi

> 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. 

Czy ktoś ma wyjaśnienia dla tego zachowania strage? Czy interpreter python naprawdę przecieka pamięć?

Jakie narzędzie są używane przez programistów Pythona do debugowania wycieków pamięci?

Odpowiedz

12

Jest cała README.valgrind w źródłach Pythona, która wyjaśnia różne zastrzeżenia, próbuje użyć Valgrind z Python:

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

Wyciek najprawdopodobniej pochodzi z własnego numeru wewnętrznego, a nie z języka Python. Duże systemy często kończą się z przydzieloną pamięcią, po prostu dlatego, że nie warto jej wyraźnie zwolnić, jeśli i tak się to skończy.

Powiązane problemy