<P> In object - oriented programming, a destructor (dtor) is a method which is automatically invoked when the object is destroyed . It can happen when its lifetime is bound to scope and the execution leaves the scope, when it is embedded in another object whose lifetime ends, or when it was allocated dynamically and is released explicitly . Its main purpose is to free the resources (memory allocations, open files or sockets, database connections, resource locks, etc .) which were acquired by the object during its life and / or deregister from other entities which may keep references to it . Use of destructors is needed for the process of Resource Acquisition Is Initialization (RAII). </P> <P> In a language with an automatic garbage collection mechanism, it would be difficult to deterministically ensure the invocation of a destructor, and hence these languages are generally considered unsuitable for RAII . In such languages, unlinking an object from existing resources must be done by an explicit call of an appropriate function (usually called Dispose ()). This method is also recommended for freeing resources, rather than using finalizers for that . </P>

When is the destructor called in object oriented programming using python
find me the text answering this question