Comment by baq

Comment by baq 2 days ago

5 replies

> Though Python is almost entirely refcounted, so one can pretty much rely on the __del__ finalizer being called.

yeah no. you need an acyclic structure to maybe guarantee this, in CPython. other Python implementations are more normal in that you shouldn't rely on finalizers at all.

sgarland 2 days ago

I love Python, but the sheer number of caveats and warnings for __del__ makes me question if this person has ever read the docs [0]. My favorite WTF:

> It is possible (though not recommended!) for the __del__() method to postpone destruction of the instance by creating a new reference to it. This is called object resurrection.

[0]: https://docs.python.org/3/reference/datamodel.html#object.__...

  • guappa 2 days ago

    How does this relate to the claim of the parent comment that cyclic structures are never freed in python (which is false, btw)?

    • sgarland 2 days ago

      When I replied, the only thing the comment said was “yeah no.” I was agreeing that __del__ is fraught with peril.

      Reading: cyclic GC, yes, the section I linked explicitly discusses that problem, and how it’s solved.

    • baq 2 days ago

      this is not what I claim, BTW.

thomashabets2 2 days ago

Author here.

Yes, yes. Hence the words "almost" and "pretty much". For exactly this reason.