1) Yes, you are right. You can even disable GC if you are sure that your code does not contain reference loops: https://docs.python.org/2/library/gc.html
Since the collector complements the reference counting already used in Python, you can disable the collector if you are sure that your program does not create reference loops. Automatic collection can be disabled by calling gc.disable ().
2) If you want to force create a collection phase, you can just call collect
3) sys.getrefcount (obj) includes a link to a function parameter, not sure if it will answer your question
4) Return get_referrers - this is not a simple list, this is a list with a dictionary containing a link to your object. Try printing a full refund, you will have something like:
[{'a': [], 'b': [], '__builtins__': <module '__builtin__' (built-in)>, '__file__': 'yourfile.py', '__package__': None, 'gc': <module 'gc' (built-in)>, 'x': {...}, '__name__': '__main__', '__doc__': None}]
You can see all links to your object as elements in the dictionary.
source share