Skip to content

Instantly share code, notes, and snippets.

@lucastamoios
Last active September 25, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucastamoios/d386f3b00263c1f207f2f17002796e40 to your computer and use it in GitHub Desktop.
Save lucastamoios/d386f3b00263c1f207f2f17002796e40 to your computer and use it in GitHub Desktop.
import ctypes
import gc
# Ctypes helps us to access unreachable objects by "memory address"
class PyObject(ctypes.Structure):
_fields_ = [("refcnt", ctypes.c_long)]
class SomeWeirdClass:
pass
gc.disable()
addr_list = []
my_rotating_list = []
for x in range(10):
some = SomeWeirdClass()
addr_list.append(id(some))
my_rotating_list.append(some)
if x % 3 == 0:
my_rotating_list = []
print(PyObject.from_address(addr_list[0]).refcnt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment