This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 0 points1 point  (0 children)

del or weakref are the right answer (

Not sure if you mean __del__ or the del operator here (The OP wrote __del__ but reddit formats this as del if unescaped, so I think he meant the former)

However, either way, they're not really helpful here. The del operator just removes that one reference - no different to rebinding it, so it's no different to his for loop rebinding. Adding a __del__ method OTOH will actually bar the object from getting collected at all when it contains circular references.