I have written some code which works without errors. The code uses MySQLdb for (frequent) database access and uses 4 different databases. Also a couple of log files are generated and logging module is used. The real worry is that when running Valgrind, i get the following
==7840== LEAK SUMMARY:
==7840== definitely lost: 29 bytes in 1 blocks
==7840== indirectly lost: 0 bytes in 0 blocks
==7840== possibly lost: 1,104,793 bytes in 8,865 blocks
==7840== still reachable: 70,684 bytes in 2,194 blocks
==7840== suppressed: 0 bytes in 0 blocks
The biggest leak is
==7840== 393,216 bytes in 1 blocks are possibly lost in loss record 1,585 of 1,585
==7840== at 0x4005903: malloc (vg_replace_malloc.c:195)
==7840== by 0x204929E: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x2054833: PyString_InternInPlace (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x20A0362: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209FB15: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x20A0075: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209FB15: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x20A0068: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x20A04CC: PyMarshal_ReadObjectFromString (in /usr/lib /libpython2.4.so.1.0)
==7840== by 0x20A1D20: PyMarshal_ReadLastObjectFromFile (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209AA63: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209CB7E: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209D9B2: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209DE71: ??? (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x209E087: PyImport_ImportModuleEx (in /usr/lib/libpython2.4.so.1.0)
==7840== by 0x207DB2D: ??? (in /usr/lib/libpython2.4.so.1.0)
So you see, It shows almost 1MB of memory as possibly lost. Is there some real problem with my code, or is it use of MySQLdb that gives such behaviour. Also to minimise it, should I explicilty free up objects (inc file, database connections) or is there a python module that I could look 开发者_JAVA技巧into?
Python uses own memory allocator on top of malloc
which causes problems when using valgrind. See Misc/README.valgrind for detailed explanation. Assuming you are not going to rebuild Python the solution is to use Misc/valgrind-python.supp as suppression file and uncomment the lines in it that suppress the warnings for PyObject_Free
and PyObject_Realloc
.
精彩评论