Garbage collection mechanism in Python | Python

Source: Internet
Author: User

--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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.