strange __del__ behavior

John Hunter jdhunter at ace.bsd.uchicago.edu
Wed Jun 9 18:40:07 CEST 2004


>>>>> "John" == John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:

    John> I have a class that uses some extension code I have written
    John> and I am trying to track down some memory leaks, which I
    John> presume to be in my extension code.  The class is question
    John> is in a python module, not extension code.  I notice some
    John> strange behavior; perhaps a guru can give me a pointer about
    John> what this may mean.

    John> If I define the __del__ method in the class C

Doh!  The class contained a circular reference, as in 

class A: pass
    
class C:
    def __init__(self):
        self.a = A()
        self.c = self
        
    def __del__(self):
        print 'bye'

c = C()

I simplified my example a bit too much!

For debugging purposes, I would like to know when C instances are
being deleted; that's why I inserted the __del__ print method.  Is
there any way to get that info w/o defining __del__ and thereby
screwing up python's garbage collection?

JDH




More information about the Python-list mailing list