# Python中的垃圾回收机制是自动回收,在回收前会调用特殊方法__del__() class A(): def __init__(self, name): self.name = name def __del__(self): print('A类被回收了') a = A('你好') print(a.name) # 你好 A类被回收了