import sys

def function(X):
    sub_function(X)

def sub_function(X):
    sub_sub_function(X)

def sub_sub_function(X):
    print(sys.getrefcount(X))
Is there a way to get the current ref count of an object in Python?