8

I have some python code where gc.collect() seems to free a lot of memory. Given Python's reference counting nature, I am inclined to think that my program contains a lot of cyclical references. Since some data structures are rather big, I would like to introduce weak references. Now I need to find the circular references, having found a few of the obvious ones, I wonder if one can detect circular references and the objects that form the ring explicitly. So far I have only seen tutorials on how to call gc.collect et. al.

4

1 Answer 1

0

Unless you are overriding the __del__ methods, you should not worry about circular dependencies, as Python is able to properly cope with them.

1
  • ... until you try to use python's multiprocessing and your objects don't pickle anymore. IMO it's a good idea to think about how to avoid cyclic references when designing an application, because it keeps several doors open to optimize performance at a later point. That's not the same as premature optimization. Nov 24, 2016 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.