Py学习  »  Python

python中析构函数的用法

Max • 3 年前 • 1213 次点击  

以下情况不会导致两次释放内存的问题吗?为什么python3会破坏一个物体 什么时候它已经被程序员破坏了?

class Example:

    # Initializing
    def __init__(self):
        print('object created.')

    # Deleting (Calling destructor)
    def __del__(self):
        print('Destructor called, object deleted.')


obj = Example()
obj.__del__()

输出:

object created.
Destructor called, object deleted.
Destructor called, object deleted.
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/128673
 
1213 次点击  
文章 [ 1 ]  |  最新文章 3 年前