Python的Object基类__del__方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chuan_day/article/details/73474686

Python的Object基类__del__方法


Python的这个方法是一个析构方法,是在实例被销毁的时候执行的,销毁实例相关的内存,方法,属性等。同样是如果基类指定了特殊的属性或者其他方法,那么子类也是需要显式的指定的。

        一般情况下无需覆盖这个方法。

Python3.4文档:

object. __del__ ( self )

Called when the instance is about to be destroyed. This is also called a destructor. If a base class has a __del__() method, the derived class’s __del__() method, if any, must explicitly call it to ensure proper deletion of the base class part of the instance. Note that it is possible (though not recommended!) for the __del__() method to postpone destruction of the instance by creating a new reference to it. It may then be called at a later time when this new reference is deleted. It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits


猜你喜欢

转载自blog.csdn.net/chuan_day/article/details/73474686