Next / Previous / Contents / TCC Help System / NM Tech homepage

26.1.5. Instance deletion: the destructor, .__del__()

When there are no values that refer to an instance any more, the storage occupied by the instance is recycled. However, if there are certain cleanup operations that must be done (such as closing external files), these operations can be placed into a destructor method that will be called before recycling the instance. Here is the general form of a destructor:

    def __del__(self):
        ...cleanup statements...