object.__del__(self)
is called when the instance is about to be destroyed.
>>> class Test:
... def __del__(self):
... print "deleted"
...
>>> test = Test()
>>> del test
deleted
Object is not deleted unless all of its references are removed(As quoted by ethan)
Also, From Python official doc reference:
del x
doesn’t directly callx.__del__()
— the former decrements the
reference count forx
by one, and the latter is only called whenx
‘s
reference count reaches zero