I have looked in the official documentation for python, but i cannot seem to find what a reference cycle is. Could anyone please clarify what it is for me, as i am trying to understand the GC module. Thank you in advance for your replies.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A reference cycle simply means one or more objects referencing each other, such that if you drew it out on paper with arrows representing the dependencies you would see a cycle.
The (almost) simplest reference cycle is having two objects
aandbthat refer to each other:Naive garbage collectors work strictly off of whether or not an object is referenced by another object. In this case, if both
aandbare not referred to by anything else, they still refer to each other and a naive garbage collector may not reclaim the memory. (I don’t know if Python can be trapped by reference cycles or not, though.)EDIT: The simplest reference cycle is an object that refers to itself: