Will the following not cause issue of freeing memory twice? Why is python3 destroying an object when it has already been destroyed by the programmer?
class Example: # Initializing def __init__(self): print('object created.') # Deleting (Calling destructor) def __del__(self): print('Destructor called, object deleted.') obj = Example() obj.__del__() Output:
object created. Destructor called, object deleted. Destructor called, object deleted.
__del__is not a destructor and does not destroy objects.__del__is not a destructor, not responsible for freeing memory, and that the object isn't necessarily destroyed after__del__even when not invoked manually.