e.g.
import gc
import ctypes as ct
a=1
address=id(a)
# this moment to del the var
del a
# and callback
gc.collect()
# now use address to get content
content=ct.cast(address,ct.py_object).value
# and print, the program show 1
print(content)
The result is like this:
Python 3.8.0 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> a = 1
>>> a
1
>>> id(a)
4334421424
>>> import gc
>>> import ctypes
>>> del a
>>> a
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
a
NameError: name 'a' is not defined
>>> gc.collect()
22
>>> ctypes.cast(4334421424, ctypes.py_object).value
1
>>>
Question: After the gc.collect(), why the address can still find the content?