--python garbage collection mechanism#python GC module (garbagecollection)--garbage collection module #The main use of reference counting to track recycling garbage;1. Reference count;#object is created or copied, reference count plus 1;--> __init__ #object reference is destroyed, reference count minus 1;-__del__ #object is no longer in use, releasing its memory;1Advantages: Real-time, any memory once no reference point will be immediately recovered;2Disadvantages: A. Additional operations to maintain reference counts, which are proportional to running memory allocations, release, reference assignment, inefficient; b. Causes circular references, references between objects, memory is never released; =list () b=list () a.append (b) B.append (a)Print(a)Print(b)>>[[[...]]] >>[[[...]]] 2. Mark-Clear#through the * * Detection method (can not understand), the object is divided into up to two parts, respectively, are retained or recycled; #the underlying use of a linked list is to connect the objects of these collections together; #Disadvantage: Process efficiency is not high;3. Generational recycling#according to the memory block survival time, the definition of three-generation object collection, the longer the survival, the less the garbage collection frequency; #In other words, the more the object is garbage collected, the longer it survives;
Garbage collection mechanism in Python | Python