Python memory leaks?

后端 未结 2 410
天命终不由人
天命终不由人 2021-01-12 11:21

I am writing a python extension that seems to be leaking memory. I am trying to figure out the soure of the problem using valgrind.

However, it seems that python it

相关标签:
2条回答
  • 2021-01-12 12:21

    The leak is most likely coming from your own extension, not from Python. Large systems often exit with memory still allocated, simply because it isn't worth it to explicitly free it if the process is about to end anyway.

    0 讨论(0)
  • 2021-01-12 12:24

    There's a whole README.valgrind in the Python sources that explains the various caveats trying to use Valgrind with 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. 
    
    0 讨论(0)
提交回复
热议问题