I am recently trying to study Python's garbage collection and I found this question.
So first let me check if my understanding is correct or not: So normally objects not contained in circular references will be garbage collected when its ref count is 0--and they should reach 0 at some point of time. So before gc is invoked, objects in circular references will not be freed as their ref counts are more than 0. When gc runs, gc can detect and free circular references. But if objects in circular ref have __del__
methods, then gc does not know what to do. So it is prorgrammer's task to manually deal with those objects through gc.garbage
.
So here, does "manually deal with" mean that I should manually break circular references? (I mean clearly call del obj
should not work)? Or there are better ways?