[Python-Dev] nested classes leaking in compiler

Christian Heimes lists at cheimes.de
Sun Mar 30 16:29:42 CEST 2008


Amaury Forgeot d'Arc schrieb:
> The approach I used is a bit brute-force, but it may work for other
> reference leaks:
> - First write a big leaking script:
>     for x in xrange(100000): leaking_function()
> - Since memory usage does not increase dramatically, it's only a
> refcount problem - no new object every time.
> - Modify the Py_INCREF macro so that it generates a breakpoint in the
> debugger when the refcount is large:
>   On Windows, it is something like:
>      if (ob->refcount > 10000) { __asm int 3; }
>   (with gdb I think you may signal SIGUSR1)
> - carefully inspect the code each time the debugger stops.
>   Fortunately, many functions can be skipped: PyDict_SetItem and other
> bullet-proof parts of the code.
>   The 20th break was the good one: a lack of symmetry between
> Py_INCREF and Py_DECREF.

Nice! Can you write a short howto for the wiki? The idea is ingenious.

Christian


More information about the Python-Dev mailing list