[pygtk] PyGObject leaking?

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 13 07:43:08 WST 2007


Mario Beauchamp wrote:
> Hi folks.
> 
> On 4/11/07, Tony Nelson <tonynelson at georgeanelson.com> wrote:
 >
> > Python will collect objects as soon as they become unreferenced.
> > Immediately.
> 
> Well, it turns out it's not immediate. Someone told me that Python 2.4
> does a collect every 700 deallocations

Both of these are each partly true. CPython will deallocate
an object immediately when its refcount drops to zero. But
if the object is part of a cycle, its refcount won't drop
to zero, even if the cycle as a whole is unreachable.

To fix that, there's a cyclic garbage collector that runs
every so often, to find unreferenced cycles and break them.

So the way to get prompt deallocation in CPython is to
break cycles explicitly, or avoid creating them in the
first place (weakrefs can help with that).

--
Greg


More information about the pygtk mailing list