Hello,
Can someone explain me why gc(CPython) can not collect recursive closure's
cycle reference? There is no __del__ there, why gc can not collect?
After many times gc collect, i also see objects like below in gc.garbage.
So i ask why gc can not collect them?
Thanks a lot.
(<cell at 0x21b36a8: function object at 0x21afb90>, <cell at 0x21b36e0: list
object at 0x20874d0>), <cell at 0x21b3718: function object at 0x21afc08>, <cell
at 0x21b3750: list object at 0x2087488>, [1], <function aa at 0x21afc08>,
(<cell at 0x21b3718: function object at 0x21afc08>, <cell at 0x21b3750: list
object at 0x2087488>), <cell at 0x21b3788: function object at 0x21afc80>, <cell
at 0x21b37c0: list object at 0x2087440>, [1], <function aa at 0x21afc80>,
(<cell at 0x21b3788: function object at 0x21afc80>, <cell at 0x21b37c0: list
object at 0x2087440>), <cell at 0x21b37f8: function object at 0x21afcf8>, <cell
at 0x21b3830: list object at 0x20873f8>, [1], <function aa at 0x21afcf8>,
(<cell at 0x21b37f8: function object at 0x21afcf8>, <cell at 0x21b3830: list
object at 0x20873f8>), <cell at 0x21b3868: function object at 0x21afd70>, <cell
at 0x21b38a0: list object at 0x20873b0>, [1], <function aa at 0x21afd70>,
(<cell at 0x21b3868: function object at 0x21afd70>, <cell at 0x21b38a0: list
object at 0x20873b0>), <cell at 0x21b38d8: function object at 0x21afde8>, <cell
at 0x21b3910: list object at 0x2087368>, [1], <function aa at 0x21afde8>,
(<cell at 0x21b38d8: function object at 0x21afde8>, <cell at 0x21b3910: list
object at 0x2087368>), <cell at 0x21b3948: function object at 0x21afe60>, <cell
at 0x21b3980: list object at 0x2087320>, [1], <function aa at 0x21afe60>,
(<cell at 0x21b3948: function object at 0x21afe60>, <cell at 0x21b3980: list
object at 0x2087320>), <cell at 0x21b39b8: function object at 0x21afed8>,
The test program is below.
#!/usr/bin/env python
import ipdb
import gc
gc.set_debug(gc.DEBUG_LEAK)
def A():
N = [1]
def aa(n):
if n in N:
return 1
else:
return n * aa(n-1)
x = 33 + aa(10)
#ipdb.set_trace()
print x
if __name__ == '__main__':
while xrange(1000):
A()
--
Best
Li Tianqing
--
https://mail.python.org/mailman/listinfo/python-list