Last active
September 25, 2019 15:31
-
-
Save lucastamoios/d386f3b00263c1f207f2f17002796e40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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