代码语言:javascript复制
'''python对象销毁(垃圾回收)'''
class Point:
'info class'
def __init__(self,x=0,y=0):
self.x = x
self.y = y
def __del__(self):
class_name = self.__class__.__name__
print(class_name, '销毁')
pt1 = Point()
pt2 = pt1
pt3 = pt2
print(id(pt1),id(pt2),id(pt3))
print(1)
del pt1
print(2)
del pt2
print(3)
del pt3
直到最后一个引用销毁
代码语言:javascript复制__del__ # 被调用