I have been playing around with Python objects in IDLE and observed that if a member variable of an object is changed, the memory isn't released! Here is an example:
import weakref
import gc
class subclass():
def __init__(self, data):
self.data=data
def __repr__(self):
return self.data.__str__()
class newclass():
def __init__(self,data):
self.data=subclass(data)
def test(self):
refs=weakref.ref(self.data)()
self.data=None
gc.collect()
print ("ref", refs)
a = newclass(data=3)
a.test()
print ("val", a.data)
The output of this code, I would expect to be:
ref None
val None
It turns out that the ref, however, is still a valid reference and the output is:
ref 3
val None
I would like to see that memory being released. I would like to understand how.