What is a good way to find all of the references to an object in python?
The reason I ask is that it looks like we have a \"memory leak\". We are up
Python's standard library has gc
module containing garbage collector API. One of the function you possible want to have is
gc.get_objects()
This function returns list of all objects currently tracked by garbage collector. The next step is to analyze it.
If you know the object you want to track you can use sys
module's getrefcount
function:
>>> x = object()
>>> sys.getrefcount(x)
2
>>> y = x
>>> sys.getrefcount(x)
3