I use this way to remove an emelment from a dict:
d["ele"] = data
...
d["ele"] = None
I think by this I can remove the reference on the original element so that the removed data can be freed, no memory leak.
Is it the right way to do this?
You remove an element from a dictionary using del
:
>>> d={}
>>> d['asdf']=3
>>> d['ele']=90
>>> d
{'asdf': 3, 'ele': 90}
>>> d['ele']=None
>>> d
{'asdf': 3, 'ele': None}
>>> del d['ele']
>>> d
{'asdf': 3}
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With