python中垃圾回收
以引用计数为主,但解决不了循环引用,以隔代回收为辅
import gc
class A():
def __init__(self):
print('object born, id:%s' % str(hex(id(self))))
def f2():
while True:
a1 = A()
a2 = A()
a1.t = a2
a2.t = a1
del a1
del a2
gc.disable()
f2()
这和链表有些类似:
原文地址:https://www.cnblogs.com/dabenniao/p/11702698.html
时间: 2024-10-15 14:27:02