This code
import gc
gc.disable()
print gc.isenabled()
print len(gc.get_objects())
class Foo(): pass
print len(gc.get_objects())
a=[]
print len(gc.get_objects())
for i in xrange(10000):
a.append(Foo())
print len(gc.get_objects())
a=[] # Should not collect
print len(gc.get_objects())
gc.collect()
print len(gc.get_objects())
Produces this output
False
3754
3755
3756
13756
3756
3374
I would expect the second to last number to be 13756, because the gc is disabled and when the original a
list goes out of scope, it should not drop those objects. Apparently python is collecting those objects anyway. Why ?
python is 2.7.2