python 销毁函数
Just like a constructor is used to create and initialize an object, a destructor is used to destroy the object and perform the final clean up.
就像使用构造函数创建和初始化对象一样,使用析构函数破坏对象并执行最终清理。
Although in python we do have garbage collector to clean up the memory, but its not just memory which has to be freed when an object is dereferenced or destroyed, it can be a lot of other resources as well, like closing open files, closing database connections, cleaning up the buffer or cache etc. Hence when we say the final clean up, it doesn't only mean cleaning up the memory resources.
尽管在python中我们确实有垃圾收集器来清理内存,但是它不仅是在取消引用或销毁对象时必须释放的内存,它还可能还有很多其他资源,例如关闭打开的文件,关闭数据库连接,清理缓冲区或缓存等。因此,当我们说最后清理时 ,这不仅意味着清理内存资源。
In our last tutorial we learned how object is created using __new__
method and initialised using the __init__
method. In this tutorial, we will learn how to destroy the object.
在上一教程中,我们学习了如何使用__new__
方法创建对象以及如何使用__init__
方法初始化对象。 在本教程中,我们将学习如何销毁对象。
As we specified clearly in the last tutorial, that __init__
method is not necessarily the constructor method as it