Debugging reference count errors; PIL problem

Martin von Loewis loewis at informatik.hu-berlin.de
Sun Jul 1 12:07:21 CEST 2001


"Edward C. Jones" <edcjones at erols.com> writes:

> 1. What is currently the easiest way to track down reference 
> count errors?

I recommend to use an advanced C debugger; gdb is good enough.  There
are actually two kinds of errors: too many decrefs, and too few
decrefs. The former means that you will access memory that has already
been freed; the latter means you have garbage.

It would help immensely if you:
a) already know what objects leak exactly, and
b) have a small test cases that shows the leak.

In gdb, set a breakpoint on allocation of your objects. The set a
watchpoint on every change to the reference counter, and watch how it
evolves.

> 2. I compiled and installed Python 2.1 with the "--with-pydebug" 
> switch for "configure". Why do even trivial programs leave a 
> large number of unDECREFed objects? 

Not sure. Which objects in particular are left at the end?

> Is there any documentation for using the reference count debugging
> features?

Not that I know of. Once you are through with your problem, you might
consider writing up some stuff.

> 3. I compiled PIL. "import _imaging" fails with the message:
> 
> ImportError: ./_imaging.so: undefined symbol: Py_InitModule4
> 
> What's going on here?

Py_InitModule4 is renamed when using --with-pydebug. You need to
recompile PIL with the installation that you've configured
--with-pydebug. Make sure you don't mix header files of both
installations, nor sys.path; the renaming was introduced to detect
errors with mixed installations.

Regards,
Martin



More information about the Python-list mailing list