Messing with the GC

Jens Thoms Toerring jt at
Mon Jan 21 02:02:22 CET 2013

Terry Reedy <tjreedy at> wrote:
> On 1/20/2013 3:09 PM, Jens Thoms Toerring wrote:

> >      thank you for the explanations. I had overlooked the
> > cyclic nature of what I had produced here and, of course,
> > the GC can't be blamed for not collecting objects that are
> > part of a cycle. The other question about the last refe-
> > rence to an object vanishing within a method call (which,
> > as I now clearly understand, can't happen and wouldn't make
> > much sense) was triggered by a segmentation fault I get
> > when I do something similar in PySide, so I was getting
> > worried if it might be due to a GC issue. Now I know its
> > got to be something different;-)

> Perhaps the hardest part of writing C extensions to CPython directly in
> C (versus something like Cython) is properly balancing increfs and
> decrefs. An incref without a later decref can lead to a memory leak. A
> decref without a preceding incref (so CPython thinks the object can be
> deleted, when it should not be) can lead to segfaults.

Definitely - I got started with Python having to write glue
code to get Python to work with a C++ library. And keeping
track of which side thinks it owns an object can sometimes
be a bit of a challenge...

> So I would report PySide code leading to segfaults to the
> PySide people.

Now that I'm more sure that it's unlikely to be a Python GC
related issue (or my not understanding what I'm doing, to be
precise) this is on my to-do list. But first I have to distill
things down to a very short example program still exhibiting
the problem - and experience tells me that this will most li-
kely result in the realization that it's not a PySide issue
at all but some misunderstanding on my side;-)

                         Best regards, Jens
  \   Jens Thoms Toerring  ___      jt at

More information about the Python-list mailing list