Firstly, I know object is destruct(or destroyed) when its __del__
function called by gc
implicitly or called explicitly. ok, why I could get the object's member variable by its reference after this object was destroyed.
python version is 3.7.1
class O():
def __init__(self):
self.name = 'I am a O'
def __del__(self):
print('Oops, O is deleted')
if __name__ == '__main__':
o = O()
c = o
print(id(o))
o.__del__()
print(c.name)
print(id(c))
The result
2473601495560
Oops, O is deleted
I am a O
2473601495560
Oops, O is deleted
We could find the problem exists, and the destruct function was called 2 times but why. thanks for help