[Patches] GC puzzle
Charles G Waldman
cgw@fnal.gov
Wed, 26 Apr 2000 10:51:35 -0500 (CDT)
I'm testing the GC patches with Py_TRACE_REFS enabled and have come
across something odd:
Python 1.6a2 (#3, Apr 26 2000, 10:35:57) [GCC 2.95.2 19991024 (release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import gc
[6007 refs]
>>> 0
0
[6011 refs]
>>> d1={}
[6015 refs]
>>> d2={}
[6019 refs]
>>> d1[0]=d2
[6021 refs]
>>> d2[0]=d1
[6023 refs]
>>> del d1
[6022 refs]
>>> del d2
[6021 refs]
>>> gc.collect()
gc: collectable <dictionary 0x81b4ac4>
gc: collectable <dictionary 0x81c4ee4>
2
[6017 refs] ### note - before I created d1 and d2 the total refs was
### 6011 - are the extra 6 references internal to the
### GVC module ?
>>> d1={} ### Now I've created a new object and the total refs has
### not gone up
[6017 refs]
>>> d2={} ### Now I've created another, and the total refs has
### gone up by 2!
[6019 refs]
>>> d1[0]=d2
[6021 refs]
>>> d2[0]=d1
[6023 refs]
>>> del d1
[6022 refs]
>>> del d2
[6021 refs]
>>> gc.collect()
gc: collectable <dictionary 0x81b4ac4>
gc: collectable <dictionary 0x81c4ee4>
2
[6017 refs] ## After this round of GC, the total refs has gone
>>> ## back to the value before d1 and d2 were created,
## as I'd expect...