我就廢話不多說了,直接上代碼吧!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
'''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 |
直到最后一個引用銷毀
1
|
__del__ # 被調用 |
以上這篇python對象銷毀實例(垃圾回收)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/ccorg/article/details/79577014