python对象销毁(垃圾回收)

发布时间:2019-09-25 08:27:38编辑:auto阅读(2151)

    '''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

    直到最后一个引用销毁

    __del__  # 被调用

关键字