Python garbage collection

后端 未结 7 1961
深忆病人
深忆病人 2020-12-05 04:38

I have created some python code which creates an object in a loop, and in every iteration overwrites this object with a new one of the same type. This is done 10.000 times,

7条回答
  •  时光取名叫无心
    2020-12-05 05:05

    I found that in my case (with Python 2.5.1), with circular references involving classes that have __del__() methods, not only was garbage collection not happening in a timely manner, the __del__() methods of my objects were never getting called, even when the script exited. So I used weakref to break the circular references and all was well.

    Kudos to Miles who provided all the information in his comments for me to put this together.

提交回复
热议问题