how soon is `__del__` called after reference count drops to zero?

后端 未结 3 1725
不思量自难忘°
不思量自难忘° 2021-01-20 00:00

How soon after the reference count reaches zero is __del__ method called? Does the language promise that it\'s done right away, before any other use code can ex

3条回答
  •  悲哀的现实
    2021-01-20 00:22

    Please read the CPython object.__del__ docs. This says most of what needs to be said, but is implementation specific; most other Python implementations don't use refcounting and so you shouldn't depend on it being called at such and such a time (or even being called at all) for functionality. It gets called at the time of destruction—which will vary between implementations.

提交回复
热议问题