1

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?

Community
  • 1
  • 1
Junchao Gu
  • 1,815
  • 6
  • 27
  • 43
  • I think `gc.garbage` is mostly a debugging aid, and "manually deal with" mostly amounts to "inspect the contents to figure out what happened and change the program to stop it from happening again". – user2357112 Jul 18 '16 at 04:19

0 Answers0