My class defines __del__ but it is not called when I delete the object.
There are several possible reasons for this.
The del statement does not necessarily call __del__ — it simply decrements the object’s reference count, and if this reaches zero __del__ is called.
If your data structures contain circular links (e.g. a tree where each child has a parent reference and each parent has a list of children) the reference counts will never go back to zero. Once in a while Python runs an algorithm to detect such cycles, but the garbage collector might run some time after the last reference to your data structure vanishes, so your __del__ method may be called at an inconvenient and random time. This is inconvenient if you’re trying to reproduce a problem. Wor