GC when Python exits

Aahz aahz at pythoncraft.com
Thu Dec 26 20:11:34 EST 2002


It's not clear to me whether GC is supposed to run at the end of a
program.  In the following code (Python 2.2.2), if you un-comment either
the for loop or gc.collect(), you'll see two instances of D() getting
reaped; otherwise only the non-cyclic instance gets __del__() run:

import gc

class C:
    pass

class D:
    def __del__(self):
        print "Bye-bye!"


a = C()
b = C()
a.b = b
b.a = a
a.d = D()

del a
del b

x = D()

l = []
#for i in range(1000):
    #l.append(C())

#gc.collect()
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I disrespectfully agree."  --SJM



More information about the Python-list mailing list