美文网首页
The Python Standard Library - Py

The Python Standard Library - Py

作者: 左心Chris | 来源:发表于2019-10-11 16:16 被阅读0次

    GC

    https://juejin.im/post/5b34b117f265da59a50b2fbe
    https://testerhome.com/topics/16556
    https://blog.csdn.net/tab_space/article/details/51939855
    最后一篇文章解释清楚了
    总的来说如下:
    先用引用计数,当引用计数为0,内存回收;
    之后用分代回收,设置threshold比如(700,10,10)
    700是分配内存的次数减去释放内存的次数
    10是0代回收的次数
    10是1代回收的次数
    接着用match sweep算法标记因为循环引用的:
    第二个步骤是将比当代处理的“代”更年轻的“代”的链表合并到当前“代”中
    https://blog.csdn.net/xiongchengluo1129/article/details/80462651

    官方指南

    https://docs.python.org/3/library/gc.html#gc.collect

    
    Set the garbage collection thresholds (the collection frequency). 
    Setting *threshold0* to zero disables collection.
    The GC classifies objects into three generations depending on how many collection
    sweeps they have survived. New objects are placed in the youngest generation
    (generation `0`). If an object survives a collection it is moved into the next older
    generation. Since generation `2` is the oldest generation, objects in that generation
    remain there after a collection. In order to decide when to run, the collector keeps track of
    the number object allocations and deallocations since the last collection. When the
    number of allocations minus the number of deallocations exceeds *threshold0*, collection
    starts. Initially only generation `0` is examined. If generation `0` has been examined more
    than *threshold1* times since generation `1` has been examined, then generation `1` is
    examined as well. Similarly, *threshold2* controls the number of collections of
    generation `1` before collecting generation `2`.
    

    相关文章

      网友评论

          本文标题:The Python Standard Library - Py

          本文链接:https://www.haomeiwen.com/subject/pqclectx.html