[Python-Dev] A "new" kind of leak
Tim Peters
tim.one@comcast.net
Sun, 14 Apr 2002 15:50:31 -0400
[Neil Schemenauer]
> PyCFunctionObject and PyMethodObject also use free lists and set the GC
> flag.
I haven't yet been able to provoke unbounded process growth using these,
although I confess I haven't dedicated my life to it <wink>. The usual
outcome is that creating one of these guys also involves creating another
kind of gc'ed object (like a class instance) that doesn't use a free list,
and that's also involved in the cycle, and then the allocations of that
latter kind of object trigger gc regularly.
For example,
import gc
gc.set_debug(gc.DEBUG_STATS)
class C:
def f(self):
self.f = self.f # create a loop
while 1:
C().f()
That creates tons of cycles, but every 1000-or-so times around the loop, the
excess of instance objects allocated triggers gc into cleaning them all up.
That prevents the bound method object free list from growing more than
1000-or-so entries too.