Surfing on the internet (here) I found that there are some problems to collect objects with __del__
method for the garbage collector.
My doubt is simple: why?
According to the documentation:
Objects that have
__del__()
methods and are part of a reference cycle cause the entire reference cycle to be uncollectable, including objects not necessarily in the cycle but reachable only from it. Python doesn’t collect such cycles automatically because, in general, it isn’t possible for Python to guess a safe order in which to run the__del__()
methods.
Why is the __del__
method so problematic? What's the difference between an object that implements it and one which doesn't? It only destroys an instance.